我尝试通过Flutter应用程序拨打电话。使用以下代码: With the following code:
UrlLauncher.launch('tel: xxxxxxxx');
我在GitHub flutter存储库上发现了此功能:https ://github.com/flutter/flutter/issues/4856
但这对我不起作用。此功能仍在Flutter中和使用哪个软件包?还是有更好的选择通过我的应用拨打电话?ne call from my app?
我尝试在Android / iOS上运行launch(“tel://214324234”),效果很好。您需要安装软件包url_launcher并将其导入 import it
import 'package:flutter/material.dart'; import 'package:url_launcher/url_launcher.dart'; class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return new MaterialApp( title: 'Flutter Demo', home: new Home(), ); } } class Home extends StatelessWidget { Home({Key key}) : super(key: key); @override Widget build(BuildContext context) => new Scaffold( appBar: new AppBar( title: new Text("View"), ), body: new Center( child: new FlatButton( onPressed: () => launch("tel://21213123123"), child: new Text("Call me")), ), ); } void main() { runApp( new MyApp(), ); }
您也可以导入它import ‘package:url_launcher/url_launcher.dart’ as UrlLauncher;,然后使用UrlLauncher.launch(“tel://21213123123”)
确保在pubspec.yaml文件的依赖项部分中包含一个条目:url_launcher:^ 1.0.21.0.2