Flutter 插件url_launcher簡介及使用,打開外部瀏覽器,撥打電話,發(fā)送短信,打開微信,支付寶,qq等

url_launcher

插件名稱:url_launcher


在這里插入圖片描述

使用Demo

import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';

class Url_launcherPage extends StatefulWidget {
  @override
  _Url_launcherPageState createState() => _Url_launcherPageState();
}

class _Url_launcherPageState extends State<Url_launcherPage> {
  @override
  Widget build(BuildContext context) {
    return Container(
      color: Colors.white,
      child: ListView(
        children: [
          textButtonItem('打開外部瀏覽器', "https://cflutter.com"),
          textButtonItem('撥打電話', "tel:10086"),
          textButtonItem('發(fā)送短信', "sms:10086"),
          textButtonItem('打開微信', "weixin://"),
          textButtonItem('打開支付寶', 'alipays://'),
          textButtonItem('打開淘寶', 'taobao://'),
          textButtonItem(
              '發(fā)送郵件', "mailto:luckly@gmail.com?subject=Test&body=測試"),
          // 協(xié)議格式:mailto:<email address>?subject=<subject>&body=<body>
        ],
      ),
    );
  }

  Widget textButtonItem(String title, String urlLink) {
    return TextButton(
      child: Text(title),
      onPressed: () async {
        // 蘋果App升級用的此方式
        // 前提是首先獲取App在蘋果里面的地址
        var url = urlLink;
        if (await canLaunch(url)) {
          await launch(url);
        } else {
          throw 'Could not launch $url';
        }
      },
    );
  }
}

打開其它應(yīng)用時,都是改變相應(yīng)的url協(xié)議地址即可,跳轉(zhuǎn)原理參照原生開發(fā)使用的url scheme,常用的如下:

QQ: mqq:// 
微信: weixin:// 
京東: openapp.jdmoble:// 測試了,好像不行
淘寶: taobao:// 
美團: imeituan:// 
點評: dianping:// 
1號店: wccbyihaodian:// 
支付寶: alipay:// 
微博: sinaweibo:// 
騰訊微博: TencentWeibo:// 
weico微博: weico:// 
知乎: zhihu:// 
豆瓣fm: doubanradio:// 
網(wǎng)易公開課: ntesopen:// 
Chrome: googlechrome:// 
QQ瀏覽器: mqqbrowser:// 
uc瀏覽器: ucbrowser:// 
搜狗瀏覽器: SogouMSE:// 
百度地圖: baidumap:// bdmap:// 
優(yōu)酷: youku:// 
人人: renren:// 
我查查: wcc:// 
有道詞典: yddictproapp:// 
微盤: sinavdisk:// 
名片全能王: camcard://
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容