Created
May 14, 2021 21:10
-
-
Save chunhtai/d4595500cfe3209eb0d694240fc99491 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Future<void> _followLink(BuildContext context) async { | |
if (!link.uri!.hasScheme || !kisWeb) { | |
// A uri that doesn't have a scheme is an internal route name. In this | |
// case, we push it via Flutter's navigation system instead of letting the | |
// browser handle it. | |
final String routeName = link.uri.toString(); | |
await pushRouteNameToFramework(context, routeName); | |
return; | |
} | |
// At this point, we know that the link is external. So we use the `launch` | |
// API to open the link. | |
final String urlString = link.uri.toString(); | |
if (await canLaunch(urlString)) { | |
await launch( | |
urlString, | |
forceSafariVC: _useWebView, | |
forceWebView: _useWebView, | |
); | |
} else { | |
FlutterError.reportError(FlutterErrorDetails( | |
exception: 'Could not launch link $urlString', | |
stack: StackTrace.current, | |
library: 'url_launcher', | |
context: ErrorDescription('during launching a link'), | |
)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment