【问题标题】:Flutter issue with launching tel: and email启动 tel: 和电子邮件时出现颤振问题
【发布时间】:2021-05-05 09:00:17
【问题描述】:

我是 Flutter 的新手,我使用 webview 制作了一个应用程序,它运行良好,但我的网络中有一个带 tel: 的 href,它没有在我的手机中打开拨号器,但在网络浏览器中运行良好。 我研究了 url_launcher 插件,但不知道在哪里放置当我点击电话时打开拨号器的代码:

我当前的代码是

import 'package:flutter/material.dart';
import 'package:flutter_webview_plugin/flutter_webview_plugin.dart';
import 'package:url_launcher/url_launcher.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return new MaterialApp(
    routes: {
    "/": (_) => new WebviewScaffold(
    url: "https://www.test.com",
    ),
    },
  );
 }
}

非常感谢您的帮助!谢谢

【问题讨论】:

    标签: flutter


    【解决方案1】:

    您可以为此使用url_launcher。这将自动打开拨号器:tel:+1 555 010 999

    _launchURL() async {
      const url = 'tel:+1 555 010 999';
      if (await canLaunch(url)) {
        await launch(url);
      } else {
        throw 'Could not launch $url';
      }
    }
    

    【讨论】:

    • 但是如何让它喜欢它检查 url,当 tel 进入 url 时,它会拨打号码..
    • 能不能把上面代码中的代码加进去让它工作
    【解决方案2】:

    首先在你的 pubspec.yaml 中添加 url_launcher 并让你的 Uri 像这样,

    final Uri _teleLaunchUri = Uri(
      scheme: 'tel',
      path: '+1 555 010 999', // your number
    );
    

    现在创建另一个函数来启动你的 Uri,

    _launchURL({Uri}) async {
      if (await canLaunch(Uri)) {
        await launch(Uri);
      } else {
        throw 'Could not launch $Uri';
      }
    }
    

    最后使用“_launchURL”函数调用你的“_teleLaunchUri”。

    onTap:(){
    _launchURL(Uri: _teleLaunchUri.toString());
    }
    

    【讨论】:

    • 知道了,但是我的网页中有一个锚标签,它有电话:..应用程序中没有颤动按钮,只是一个带有数字 asn 锚的网页视图,它也可以使用吗?
    • 并且数字在锚标签上,不是硬编码
    • 你能分享你的网页浏览网址吗?
    • 使用 webview_flutter 代替 url_launcher。在 webview 中设置您的 webview url 并在真实设备上打开它。当您点击号码链接时,它将在您的手机上打开拨号器。
    • 它实际上并没有打开拨号器
    猜你喜欢
    • 2020-01-19
    • 2021-05-10
    • 2019-12-31
    • 2023-03-28
    • 2020-10-24
    • 2019-03-04
    • 2019-01-07
    • 1970-01-01
    • 2021-09-26
    相关资源
    最近更新 更多