Open reyesmfabian opened 3 years ago
I added a global variable. Listener start to work after init. But you should get uniLink before listener. getInitialLink() or getInitialUri() will help you. You can manage url or urllink in your app.
Future checkDeepLink(LocalizationDelegate delegate) async { StreamSubscription _sub; try { await UniLink.getInitialLink(); _sub = UniLink.uriLinkStream.listen((Uri uri) { WidgetsFlutterBinding.ensureInitialized(); runApp(LocalizedApp(delegate, MyApp())); }, onError: (err) { // Handle exception by warning the user their action did not succeed _sub.cancel(); print("onError"); });
/////// please add this code here try { uniLink = await getInitialLink(); //uniLink is global variable for use in initstate(). you can check when uiLink is empty/not. } on PlatformException { uniLink = 'Failed to get initial link.'; } on FormatException { uniLink = 'Failed to parse the initial link as Uri.'; } //////
} on PlatformException { print("PlatformException"); _sub.cancel(); } on Exception { print('Exception thrown'); _sub.cancel(); } }
I added a global variable. Listener start to work after init. But you should get uniLink before listener. getInitialLink() or getInitialUri() will help you. You can manage url or urllink in your app.
Future checkDeepLink(LocalizationDelegate delegate) async { StreamSubscription _sub; try { await UniLink.getInitialLink(); _sub = UniLink.uriLinkStream.listen((Uri uri) { WidgetsFlutterBinding.ensureInitialized(); runApp(LocalizedApp(delegate, MyApp())); }, onError: (err) { // Handle exception by warning the user their action did not succeed _sub.cancel(); print("onError"); });
You are calling runApp()
in the stream's listen
method? Everytime a link opens the app, when the app is in background, it will cal the runApp()
method.
I configured everything according to the documentation and it works fine, except that when the application is finished the link does not allow navigation. To make it work I have to open the application first and then click on the link.
main.dart
home.dart
Here I read the stream and generate the navigation