Flutter之點擊按鈕打開百度鏈接

1 需求

點擊按鈕,打開百度鏈接

 

 
2 代碼實現(xiàn)

     
    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 運行效果

 










作者:chen.yu
深信服三年半工作經(jīng)驗,目前就職游戲廠商,希望能和大家交流和學(xué)習(xí),
微信公眾號:編程入門到禿頭 或掃描下面二維碼
零基礎(chǔ)入門進(jìn)階人工智能(鏈接)