Skip to content

Instantly share code, notes, and snippets.

@marsgpl
Last active May 11, 2020 13:42
Show Gist options
  • Save marsgpl/c34fd2a3bdef093defcd6d52153e3de1 to your computer and use it in GitHub Desktop.
Save marsgpl/c34fd2a3bdef093defcd6d52153e3de1 to your computer and use it in GitHub Desktop.
Flutter open url
import 'package:url_launcher/url_launcher.dart';
Future<bool> openUrl(String url) async {
if (url == null || url.trim().length == 0) {
return false;
}
url = Uri.encodeFull(url.trim());
if (!url.contains('://')) {
url = 'https://$url';
}
if (!await canLaunch(url)) {
return false;
}
await launch(url, forceSafariVC: false);
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment