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'),
              ),
            ),
          ),
      );
  }
}

Flutter之点击按钮打开百度链接Flutter之点击按钮打开百度链接

上一篇:Jmeter中发出请求后的接收的response data乱码


下一篇:《Cocos2d 跨平台游戏开发指南(第2版)》一1.10 绘制gIPrimitives