I am building a Flutter app, and I'd like to open a URL into a web browser or browser window (in response to a button tap). But I am unable to open it.
This my code-
import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: ElevatedButton(
onPressed: _launchURL,
child: new Text('FLutter'),
),
),
));
_launchURL() async {
const url = 'https://flutter.io';
final uri = Uri.parse(url);
if (await canLaunchUrl(uri)) {
await launchUrl(uri);
} else {
throw 'Could not launch $url';
}
}