Flutter之点击按钮打开百度链接
1 需求
点击按钮,打开百度链接
2 代码实现
import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';
void main() {
runApp(MyApp1());
}
class MyApp1 extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'open url',
home: Scaffold(
appBar: AppBar(
// Here we take the value from the MyHomePage object that was created by
// the App.build method, and use it to set our appbar title.
title: Text('hello flutter'),
),
body: Center(
child: RaisedButton(
onPressed: () {
const url = 'https://www.baidu.com';
launch(url);
},
child: Text('open baidu'),
),
),
),
);
}
}
3 运行效果
赞 (0)