text
stringlengths
1
474
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'URL Launcher',
theme: ThemeData(
colorSchemeSeed: Colors.purple,
brightness: Brightness.light,
),
home: const MyHomePage(title: 'URL Launcher'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
Future<void>? _launched;
Future<void> _launchInBrowser(Uri url) async {
if (!await launchUrl(
url,
mode: LaunchMode.externalApplication,
)) {
throw Exception('Could not launch $url');
}
}
Future<void> _launchInWebView(Uri url) async {
if (!await launchUrl(
url,
mode: LaunchMode.inAppWebView,
)) {
throw Exception('Could not launch $url');
}
}
Widget _launchStatus(BuildContext context, AsyncSnapshot<void> snapshot) {
if (snapshot.hasError) {
return Text('Error: ${snapshot.error}');
} else {
return const Text('');
}
}
@override
Widget build(BuildContext context) {
final Uri toLaunch = Uri(
scheme: 'https',
host: 'docs.flutter.dev',
path: 'testing/native-debugging');
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Padding(
padding: const EdgeInsets.all(16),
child: Text(toLaunch.toString()),
),
FilledButton(
onPressed: () => setState(() {
_launched = _launchInBrowser(toLaunch);
}),
child: const Text('Launch in browser'),
),
const Padding(padding: EdgeInsets.all(16)),
FilledButton(
onPressed: () => setState(() {
_launched = _launchInWebView(toLaunch);
}),
child: const Text('Launch in app'),
),
const Padding(padding: EdgeInsets.all(16.0)),
FutureBuilder<void>(future: _launched, builder: _launchStatus),
],
),
),
);
}
}<code_end>
To add the url_launcher package as a dependency,
run flutter pub add:To check what changed with the codebase:In Linux or macOS, run this find command.In Windows, run this command in the command prompt.Installing url_launcher added config files and code files
for all target platforms in the Flutter app directory.<topic_end>
<topic_start>
Debug Dart and native language code at the same time
This section explains how to debug the Dart code in your Flutter app
and any native code with its regular debugger.
This capability allows you to leverage Flutter’s hot reload
when editing native code.<topic_end>
<topic_start>
Debug Dart and Android code using Android Studio
To debug native Android code, you need a Flutter app that contains
Android code. In this section, you learn how to connect
the Dart, Java, and Kotlin debuggers to your app.
You don’t need VS Code to debug both Dart and Android code.
This guide includes the VS Code instructions to be consistent
with the Xcode and Visual Studio guides.These section uses the same example Flutter url_launcher app created
in Update test Flutter app.info Note