Closed LinschotenMelle closed 12 months ago
Links are handled by the system and the application is called from it, there's is nothing we can do to bypass this.
The only thing you could do as a workaround is to set a lock in the listener. When you launch your re-entrant URL, you could skip the default behaviour.
Hi everyone,
Currently we've got a problem with our Flutter app and Applinks. The app can be opened via deep links and we can display content based on these links. However, we have a big problem with outgoing links in the app.
Our app accepts app all incoming URL's and handles them inside the app. If the URL is not recognized in the app we use
URLUtils.launchURLExternal(url)
to go to the web instead of app. The only issue is that makes the applink infinite loop because we go back to a page that sends the page to the app.Is there a way/workaround to prevent it from infinite looping
// app.dart StreamSubscription? _linkSubscription;
Future _handleIncomingLinks() async {
final appLinks = sl();
final uri = await appLinks.getInitialAppLink();
// Handle link when app is in warm state (front or background) _linkSubscription = appLinks.uriLinkStream.listen((uri) { sl().handle(uri);
});
// Handle initial link if app was in cold state (terminated) if (uri != null) { await sl().handle(uri);
}
}
// AppLinkService Future handle(Uri uri) async {
try {
if (uri.path.endsWith('.html')) {
// PDP
await appLinkProductService.handlePDP(uri: uri);
} else if (regExpCatagoryPage.hasMatch(uri.path)) {
// Categories
await appLinkAssortmentService.handleAssortment(uri: uri);
} else {
await crashlytics.log('Unable to handle applink uri $uri');
return launchURLExternal(uri);
}
} catch (e, s) {
await crashlytics.recordError(e, s);
return launchURLExternal(uri);
}
}
Future launchURLExternal(Uri uri) async {
await URLUtils.launchURLExternal(uri.toString());
}