如何通过Flutter应用拨打电话 [英] How to make a phone call from a flutter app
问题描述
我尝试通过Flutter应用程序拨打电话.使用以下代码:
I try to make a phone call from my Flutter app. With the following code:
UrlLauncher.launch('tel: xxxxxxxx');
我在GitHub flutter存储库中找到了此函数: https://github.com/flutter /flutter/issues/4856
I found this Function on the GitHub flutter repo: https://github.com/flutter/flutter/issues/4856
但这对我不起作用.此功能仍在Flutter中和使用哪个软件包?还是有更好的选择通过我的应用拨打电话?
But this doesn't work for me. Is this Function still in Flutter and in which package? Or is there a better option to do a phone call from my app?
推荐答案
我在Android/iOS上尝试了此launch("tel://214324234")
,并且效果很好.
您需要安装软件包 url_launcher 并导入
I tried on Android/iOS this launch("tel://214324234")
and it works well.
You need to install package url_launcher and 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")
Also you can import it import 'package:url_launcher/url_launcher.dart' as UrlLauncher;
and then use UrlLauncher.launch("tel://21213123123")
请确保在pubspec.yaml文件的依赖项"部分中包含该条目: url_launcher:^ 1.0.2
Be sure to include an entry for it in the pubspec.yaml file, in the dependencies section: url_launcher: ^1.0.2
这篇关于如何通过Flutter应用拨打电话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!