Skip to content

Instantly share code, notes, and snippets.

@chunhtai
Created May 14, 2021 21:10
Show Gist options
  • Save chunhtai/d4595500cfe3209eb0d694240fc99491 to your computer and use it in GitHub Desktop.
Save chunhtai/d4595500cfe3209eb0d694240fc99491 to your computer and use it in GitHub Desktop.
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