flutter 打开第三方应用

1.url_launcher安装

2.引用(就是Url不一样)

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

class OpenThree extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(
      appBar: AppBar(
        title: Text("第三方应用"),
      ),
      body: Column(
        children: <Widget>[
          DecoratedBox(
            decoration: BoxDecoration(color: Colors.blueAccent),
            child: ListTile(
              title: Text("打开浏览器"),
              onTap: _lanchUrl,
              leading: Icon(Icons.open_in_browser),
            ),
          ),
          DecoratedBox(
            decoration: BoxDecoration(color: Colors.deepPurple),
            child: ListTile(
              title: Text("打开App"),
              onTap: _lanchApp,
              leading: Icon(Icons.apps),
            ),
          ),
          DecoratedBox(
            decoration: BoxDecoration(color: Colors.lightGreen),
            child: ListTile(
              title: Text("打电话"),
              onTap: _lanchTel,
              leading: Icon(Icons.apps),
            ),
          ),
          DecoratedBox(
            decoration: BoxDecoration(color: Colors.redAccent),
            child: ListTile(
              title: Text("sms发消息"),
              onTap: _lanchSms,
              leading: Icon(Icons.apps),
            ),
          ),
          DecoratedBox(
            decoration: BoxDecoration(color: Colors.blueGrey),
            child: ListTile(
              title: Text("发邮件"),
              onTap: _lanchEmail,
              leading: Icon(Icons.apps),
            ),
          )
        ],
      ),
    );
  }

  //打开浏览器查看页面
  _lanchUrl() async {
    final url = "https://www.baidu.com";
    if (await canLaunch(url)) {
      await launch(url);
    } else {
      throw "不可以加载浏览器地址:$url";
    }
  }

  //打开app

  _lanchApp() async {
    const url = "geo:31.2651321247,120.7324430486";
    const iosUrl = "http://maps.apple.com/?ll=31.2651321247,120.7324430486";
    if (await canLaunch(url)) {
      await launch(url);
    } else if (await canLaunch(iosUrl)) {
      await launch(iosUrl);
    }else{
      throw "不可以打开App";
    }
  }

  //打电话

  _lanchTel() async {
     final url = "tel:+1 555 010 999";
    if (await canLaunch(url)) {
      await launch(url);
    } else {
      throw "不可以打电话";
    }
  }

  //发sms
  _lanchSms() async {
     final url = "sms:5550101234";
    if (await canLaunch(url)) {
      await launch(url);
    } else {
      throw "不可sms";
    }
  }

  //发邮件
  _lanchEmail() async {
     final url = "mailto:smith@example.org?subject=News&body=New%20plugin";
    if (await canLaunch(url)) {
      await launch(url);
    } else {
      throw "不可发邮件";
    }
  }
}

 浏览器:

      

 APP:

打电话:

 Sms消息:

发邮件:

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值