Я пробовал ждать загрузки приложения, задерживать навигацию по gorouter на несколько секунд и выполнять еще несколько действий, но это просто не работает.
GoRouter называется appRouter.
/>Когда приложение находится в фоновом режиме, оно работает нормально, но оно должно работать и когда оно не работает.
Код: Выделить всё
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State createState() => _MyAppState();
}
class _MyAppState extends State {
late AppLinks _appLinks;
late dynamic _sub;
Uri? _pendingInitialUri;
bool deadStartHandled = false;
@override
void initState() {
super.initState();
_initAppLinks();
}
Future _initAppLinks() async {
_appLinks = AppLinks();
// cold start
final initialUri = await _appLinks.getInitialLink();
if (initialUri != null) {
_pendingInitialUri = initialUri;
if (!mounted) return;
_handleIncomingLink(_pendingInitialUri!, true);
deadStartHandled = true;
_pendingInitialUri = null;
} else {
// app is running
_sub = _appLinks.uriLinkStream.listen(
(Uri? uri) {
if (uri != null) {
deadStartHandled = false;
_handleIncomingLink(uri, false);
}
},
);
}
}
void _handleIncomingLink(Uri uri, bool appStart) {
if (uri.scheme == 'appname' &&
(uri.path == '/' || uri.toString() == 'appname://')) {
debugPrint('Custom scheme URL intercepted: $uri');
return;
} else {
if (appStart) {
//this one sends directly to '/' but nothing happens
context.go(uri.path);
//this one shows a black screen
//appRouter.go(uri.path);
} else {
appRouter.go(uri.path);
}
return;
}
}
@override
void dispose() {
super.dispose();
_sub.cancel();
}
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
context.read();
return MaterialApp.router(
localizationsDelegates: const [
AppLocalizations.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
supportedLocales: const [
Locale('sv'),
],
title: 'AppName',
theme: AppTheme().getTheme(),
routerConfig: appRouter,
builder: (context, child) {
return Stack(
children: [
child!,
if (context.watch().shouldShowLoader)
LoadingScreen(context: context),
],
);
},
);
}
}
Код: Выделить всё
WidgetsBinding.instance.addPostFrameCallback((_) {
if (_pendingInitialUri != null) {
_handleIncomingLink(_pendingInitialUri!, deadStartHandled);
_pendingInitialUri = null;
}
});
Похоже, что это постоянная проблема с Flutter как для IOS, так и для Android.
Подробнее здесь: https://stackoverflow.com/questions/798 ... een-for-me
Мобильная версия