• Flutter 的url_launcher简介


    url_launcher是用于在移动平台中启动URL的Flutter插件,适用于IOS和Android平台。他可以打开网页,发送邮件,还可以拨打电话。

    github地址:https://github.com/flutter/plugins/tree/master/packages/url_launcher

    引入依赖

    pubspec.yaml文件里注册依赖,并保存下载包。请注意使用最新版。

    url_launcher: ^5.1.3

    在需要使用的页面在使用import引入具体的url_launcher包。

    import 'package:url_launcher/url_launcher.dart';

    支持的URL方案

    方案Action
    http:<URL>https:<URL> 例如 http://flutter.dev 在默认浏览器中打开URL

    mailto:<email address>?subject=<subject>&body=<body>

    例如

    mailto:smith@example.org?subject=News&body=New%20plugin

    在默认电子邮件应用中创建电子邮件
    tel:<phone number>, 例如 tel:+1 555 010 999 拨打电话以使用默认电话应用程序
    sms:<phone number>, 例如 sms:5550101234 使用默认消息传递应用程序发送SMS消息 

    代码示例:

        String url = 'tel:12306' ;
        if(await canLaunch(url)){
          await launch(url);
        }else{
          throw 'url不能进行访问,异常。';
        }
    
    //或者
    
        String url = 'https://www.baidu.com';
        if(await canLaunch(url)){
          await launch(url);
        }else{
          throw 'url不能进行访问,异常。';
        }
  • 相关阅读:
    63.Unique Paths II
    Java中的访问修饰符
    Java語言
    JRE与JDK
    Linux中ls命令详解
    硬盘主分区和拓展分区
    java中的静态初始化块
    java中的静态变量
    java中的静态方法
    java构造方法
  • 原文地址:https://www.cnblogs.com/joe235/p/11540321.html
Copyright © 2020-2023  润新知