Flutter:深度链接工作正常,但在 Android 上应用程序关闭时需要两次调用

问题描述 投票:0回答:1

我正在尝试在我的 flutter 应用程序中实现深度链接。

当应用程序打开或处于待机状态时,它可以完美运行。 当应用程序在 IOS 上关闭时它也可以工作。

我的问题是在 Android 上,当我从深层链接网址打开应用程序时,应用程序卡在白屏上。 第二次单击该网址会正确转到右侧屏幕。

这是我用于深度链接的包:https://pub.dev/packages/app_linkshttps://pub.dev/packages/auto_route#deep-linking

这些是 Android 模拟器上的错误的屏幕截图:

第一个电话

第二次通话

android flutter deep-linking
1个回答
0
投票

路由器的代码

@AutoRouterConfig()
class AppRouter extends $AppRouter {
  static const defaultTransitionBuilder = TransitionsBuilders.slideLeft;

  @override
  List<AutoRoute> get routes => [
        AdaptiveRoute(
          page: SplitterRoute.page,
          guards: [ConfigGuard()],
          initial: true,
        ),
        AdaptiveRoute(page: MaintenanceRoute.page),
        AdaptiveRoute(page: RequiredVersionRoute.page),
        AdaptiveRoute(page: LatestVersionRoute.page),
        AdaptiveRoute(
          path: "/",
          page: ContentRoute.page,
          guards: [AuthGuard()],
          children: [
            AdaptiveRoute(
              page: UserRoute.page,
              initial: true,
              children: [
                AdaptiveRoute(
                  path: "hairdresser",
                  page: HairdresserRoute.page,
                  children: [
                    AdaptiveRoute(path: "home", page: HomeRoute.page),
                    AdaptiveRoute(
                      path: "search",
                      page: SearchRoute.page,
                      children: [
                        AdaptiveRoute(
                            path: "list-offers", page: JobOffersRoute.page),
                        AdaptiveRoute(path: "map-offers", page: MapRoute.page),
                      ],
                    ),
                    AdaptiveRoute(path: "profile", page: ProfileRoute.page),
                  ],
                ),
                AdaptiveRoute(
                  page: ManagerRoute.page,
                  children: [
                    AdaptiveRoute(page: SalonMapRoute.page),
                    AdaptiveRoute(page: RedirectBrowserRoute.page),
                  ],
                ),
                AdaptiveRoute(page: AcceptGcuRoute.page),
              ],
            ),
            AdaptiveRoute(page: JobRoute.page),
            AdaptiveRoute(page: ApplicationRoute.page),
            AdaptiveRoute(page: SavedJobOffersRoute.page),
            AdaptiveRoute(page: ProfileSheetRoute.page),
            AdaptiveRoute(page: ProfilePictureRoute.page),
            AdaptiveRoute(page: PersonalInfoFormRoute.page),
            AdaptiveRoute(page: ContractWantedRoute.page),
            AdaptiveRoute(page: LevelRoute.page),
            AdaptiveRoute(page: LanguageRoute.page),
            AdaptiveRoute(page: GeographicalAvailabilityRoute.page),
            AdaptiveRoute(page: FormationRoute.page),
            AdaptiveRoute(page: ExperienceRoute.page),
            AdaptiveRoute(page: BrandKnowledgeRoute.page),
            AdaptiveRoute(page: TechnicalSkillRoute.page),
            AdaptiveRoute(page: PersonalSkillRoute.page),
            AdaptiveRoute(page: RelationalSkillRoute.page),
            AdaptiveRoute(page: CreationRoute.page),
            AdaptiveRoute(
              page: VideoRoute.page,
              children: [
                AdaptiveRoute(page: CurrentVideoRoute.page),
                AdaptiveRoute(page: NewVideoRoute.page),
              ],
            ),
            CustomRoute(
              page: SettingsRoute.page,
              transitionsBuilder: defaultTransitionBuilder,
            ),
          ],
        ),
        AdaptiveRoute(page: AdvantageRoute.page),
        AdaptiveRoute(page: SignUpRoute.page),
        CustomRoute(
          page: SignInRoute.page,
          transitionsBuilder: defaultTransitionBuilder,
        ),
        CustomRoute(
          page: PasswordRecoveryRoute.page,
          transitionsBuilder: defaultTransitionBuilder,
        ),
      ];
}

还有我的主要

Future main({final bool testing = false}) async {
  if (!kReleaseMode) {
    await dotenv.load(fileName: ".env");
  } else {
    await dotenv.load(fileName: ".env.prod");
  }

  HttpOverrides.global = MyHttpOverrides();

  WidgetsFlutterBinding.ensureInitialized();
  PlatformDispatcher.instance.onError = (exception, stackTrace) {
    log(
      "An error occured while the app execution here is the stacktrace :",
      stackTrace: stackTrace,
      error: exception,
    );
    return true;
  };

  await Firebase.initializeApp(
    options: DefaultFirebaseOptions.currentPlatform,
  );

  SystemChrome.setSystemUIOverlayStyle(
    const SystemUiOverlayStyle(
      systemNavigationBarColor: Style.background,
      systemNavigationBarIconBrightness: Brightness.dark,
      statusBarIconBrightness: Brightness.dark,
      statusBarBrightness: Brightness.light,
    ),
  );

  await SystemChrome.setPreferredOrientations([
    DeviceOrientation.portraitUp,
    DeviceOrientation.portraitDown,
  ]);

  SystemInitializer.setupInternalMemory();
  SystemInitializer.setupExceptions();

  if (!testing) {
    SystemInitializer.setupServices(AuthClient(), ApiClient(), Dio());
  }

  runApp(const App());
}

class App extends StatelessWidget {
  const App({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return BlocProvider(
      create: (context) => AuthBloc(),
      child: GestureDetector(
        onTap: () {
          if (FocusManager.instance.primaryFocus?.hasPrimaryFocus ?? false) {
            FocusManager.instance.primaryFocus?.unfocus();
          }
        },
        child: _buildApplication(context),
      ),
    );
  }

  MaterialApp _buildApplication(BuildContext context) {
    return MaterialApp.router(
      routerConfig: getIt<AppRouter>().config(
        includePrefixMatches: true,
      ),
      localizationsDelegates: const [
        ...AppLocalizations.localizationsDelegates,
        PhoneFieldLocalization.delegate,
      ],
      supportedLocales: AppLocalizations.supportedLocales,
      theme: ThemeData(
        scaffoldBackgroundColor: Style.background,
        textTheme: const TextTheme(
          bodyMedium: TextStyle(fontFamily: "MPLUS_Medium"),
          titleLarge: TextStyle(fontSize: 22, fontFamily: "MPLUS_Black"),
          titleMedium: TextStyle(fontFamily: "MPLUS_Black"),
          titleSmall: TextStyle(fontFamily: "MPLUS_Light"),
        ),
        primarySwatch: const MaterialColor(
          0xFF10e5da,
          {
            50: Color.fromRGBO(16, 229, 219, .1),
            100: Color.fromRGBO(16, 229, 219, .2),
            200: Color.fromRGBO(16, 229, 219, .3),
            300: Color.fromRGBO(16, 229, 219, .4),
            400: Color.fromRGBO(16, 229, 219, .5),
            500: Color.fromRGBO(16, 229, 219, .6),
            600: Color.fromRGBO(16, 229, 219, .7),
            700: Color.fromRGBO(16, 229, 219, .8),
            800: Color.fromRGBO(16, 229, 219, .9),
            900: Color.fromRGBO(16, 229, 219, 1),
          },
        ),
        buttonTheme: const ButtonThemeData(buttonColor: Colors.black),
      ),
      debugShowCheckedModeBanner: Environment.debugMode,
    );
  }
}

我希望它能有所帮助:D

编辑:好的,我成功了! 我在我的主 MaterialApp.router() 中添加了一个 deeplinkbuilder,现在当 Android 应用程序关闭时,我调用

 adb shell "am start -a android.intent.action.VIEW -d app://zestee.fr/hairdresser/profile"

几秒钟后,它在白屏上打开了右侧屏幕。

抱歉这个主题,我将关闭它或删除它。

https://i.stack.imgur.com/F1N7f.png

© www.soinside.com 2019 - 2024. All rights reserved.