美文网首页Flutter开发圈
Flutter url_launcher用法

Flutter url_launcher用法

作者: zda123000 | 来源:发表于2019-03-06 21:55 被阅读684次

    一款支持android和IOS的插件,其中包含打开网址、发送邮件、拨打电话、以及发送信息功能。

    事例项目地址

    git地址

    实例 作用
    http:<URL> , https:<URL>, e.g. http://flutter.io 在默认浏览器中打开网址
    mailto:<email address>?subject=<subject>&body=<body>, e.g. mailto:smith@example.org?subject=News&body=New%20plugin 发送邮件
    tel:<phone number>, e.g. tel:+1 555 010 999 拨打电话
    sms:<phone number>, e.g. sms:5550101234 发送信息
    拨打电话
    import 'package:url_launcher/url_launcher.dart';
    
    ......
    
    class LeaderPhone extends StatelessWidget {
      final String leaderPhone;  // 电话号码
    
      LeaderPhone({Key key, this.leaderImage, this.leaderPhone}) : super(key: key);
    
      @override
      Widget build(BuildContext context) {
        return Container(
          child: InkWell(
            onTap: _launchURL,
            child: Image.network(leaderImage),
          ),
        );
      }
    
      void _launchURL() async {
        String url='tel:'+leaderPhone;
        if(await canLaunch(url)) {
          await launch(url);
        } else {
          print('不能访问');
        }
      }
    }
    
    效果图

    项目地址

    其他方式类似,重要的是遵守他的规则

    相关文章

      网友评论

        本文标题:Flutter url_launcher用法

        本文链接:https://www.haomeiwen.com/subject/tgaxpqtx.html