In this tutorial, we’ll learn how we can launch a url in flutter mobile applications. For this we can use a flutter package called url_launcher.
First we need to create a new Flutter Project and then we will add our plugin into the pubspec.yaml file.
dependencies:
flutter:
sdk: flutter
url_launcher: ^5.2.7
First to open website url into your app you need to create a method with website url.
myUrl() async {
const url = 'https://www.google.com/maps/@18.8154265,76.7751435,7z';
if (await canLaunch(url)) {
await launch(url);
} else {
throw 'Could not launch $url';
}
}
we’ve created a method named myUrl and inside this method we’ve written the code for opening the google map in the browser.
Call this method on onPress of button
RaisedButton(
child: Text('Launch Url'),
onPressed: () {
myUrl();
},
);
And thats solve