Skip to content

Commit 384b7f0

Browse files
committed
Use SchedulerBinding to only handle links when they're ready
1 parent 2ed7dc1 commit 384b7f0

1 file changed

Lines changed: 7 additions & 9 deletions

File tree

lib/main.dart

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -498,21 +498,19 @@ class _FinampState extends State<Finamp> with WindowListener {
498498
@override
499499
void initState() {
500500
super.initState();
501-
// Subscribe to all events (initial link and further)
502-
_uriLinkSubscription = AppLinks().uriLinkStream.listen((uri) async {
503-
linkHandlingLogger.info("Received link: $uri");
504-
int attempts = 0;
505-
do {
501+
502+
SchedulerBinding.instance.addPostFrameCallback((_) {
503+
_uriLinkSubscription = AppLinks().uriLinkStream.listen((uri) async {
504+
linkHandlingLogger.info("Received link: $uri");
506505
var context = GlobalSnackbar.materialAppNavigatorKey.currentContext;
507506
if (context != null) {
508507
if (uri.host == "internal") {
509508
await Navigator.of(context).pushNamed(uri.path);
510509
}
511-
break;
510+
} else {
511+
linkHandlingLogger.warning("No context available to handle link");
512512
}
513-
// Wait for the context to be available
514-
await Future<void>.delayed(const Duration(milliseconds: 250));
515-
} while (++attempts < 10);
513+
});
516514
});
517515

518516
// If the app is running on desktop, we add a listener to the window manager

0 commit comments

Comments
 (0)