import 'package:flutter/material.dart'; import 'package:url_launcher/url_launcher.dart'; final Uri _url = Uri.parse('https://flutter.dev'); class TestScreen extends StatelessWidget { const TestScreen({Key? key}) : super(key: key); @override Widget build(BuildContext context) { return const Scaffold( body: _Body(), ); } } class _Body extends StatelessWidget { const _Body(); @override Widget build(BuildContext context) { return const Center( child: Center( child: ElevatedButton( onPressed: _launchUrl, child: Text('Show Flutter homepage'), ), ), ); } } Future _launchUrl() async { if (!await launchUrl(_url)) { throw Exception('Could not launch $_url'); } }