• 调用 url_launcher 模块打开外部浏 览器 打开外部应用 拨打电话 发送短信


    1、Flutter url_launcher 模块
       Flutter url_launcher 模块可以让我们实现打开外部浏览器、打开外部应用、发送短信、拨打电话等功能。
       https://pub.dev/packages/url_launcher
     
    2、关于打开其他 app 请参考这个帖子
    https://www.cflutter.com/topic/5d0853733b57e317a4d0af01
     
     
    案例代码
    import 'package:flutter/material.dart';
    import 'package:url_launcher/url_launcher.dart';

    class UrlLauncher extends StatefulWidget {
    UrlLauncher({Key key}) : super(key: key);

    _UrlLauncherState createState() => _UrlLauncherState();
    }

    class _UrlLauncherState extends State<UrlLauncher> {
    @override
    Widget build(BuildContext context) {
    return Scaffold(
    appBar: AppBar(
    title: Text('UrlLauncher'),
    ),
    body: Center(
    child: Padding(
    padding: EdgeInsets.all(20),
    child: ListView(children: [
    RaisedButton(
    child: Text('打开外部浏览器'),
    onPressed: () async{
    const url = 'https://cflutter.com';
    if (await canLaunch(url)) {
    await launch(url);
    } else {
    throw 'Could not launch $url';
    }
    },
    ),
    SizedBox(height: 10),
    RaisedButton(
    child: Text('拨打电话'),
    onPressed: () async{
    var tel = 'tel:10086';
    if (await canLaunch(tel)) {
    await launch(tel);
    } else {
    throw 'Could not launch $tel';
    }

    },
    ),
    SizedBox(height: 10),
    RaisedButton(
    child: Text('发送短信'),
    onPressed: () async{
    var tel = 'sms:10086';
    if (await canLaunch(tel)) {
    await launch(tel);
    } else {
    throw 'Could not launch $tel';
    }
    },
    ),
    SizedBox(height: 10),
    RaisedButton(
    child: Text('打开外部应用'),
    onPressed: () async{
    /*
    weixin://
    alipays://
    */
    var url = 'alipays://';
    if (await canLaunch(url)) {
    await launch(url);
    } else {
    throw 'Could not launch $url';
    }

    },
    )
    ]),
    )));
    }
    }
  • 相关阅读:
    w3cscholl的在线代码编辑工具2
    w3cscholl的在线代码编辑工具
    关于 stl的内存分配的深浅拷贝
    色彩模式与色彩空间
    mediacoder固定质量CRF
    集合加泛型的类型转换
    JQuery事件绑定bind、live、on、trigger
    JS构造函数中有return
    SSA与ASS字幕
    同步、异步、阻塞、非阻塞区别与联系
  • 原文地址:https://www.cnblogs.com/zhaofeis/p/12375130.html
Copyright © 2020-2023  润新知