gpt-3.5-turbo-0613· openai
Suzhen/CodeChat
url_launcher flutter sample
- User
url_launcher flutter sample
- Assistant
Here is a sample code using the url_launcher package in Flutter:
dartimport 'package:flutter/material.dart'; import 'package:url_launcher/url_launcher.dart'; void main() => runApp(MyApp()); class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( title: 'URL Launcher Sample', theme: ThemeData( primarySwatch: Colors.blue, ), home: LaunchURLScreen(), ); } } class LaunchURLScreen extends StatelessWidget { final String _url = 'https://www.example.com'; void _launchURL() async { if (await canLaunch(_url)) { await launch(_url); } else { throw 'Could not launch $_url'; } } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text('URL Launcher Sample'), ), body: Center( child: RaisedButton( onPressed: _launchURL, child: Text('Launch URL'), ), ), ); } }