我尝试通过我的 Flutter 应用调用电话。使用以下代码:
UrlLauncher.launch('tel: xxxxxxxx');
我在 GitHub Flutter 存储库中找到了这个函数:https://github.com/flutter/flutter/issues/4856
但这对我不起作用。这个函数是否还在 Flutter 中,在哪个包中?还是有更好的选择可以通过我的应用调用电话?
最佳答案
从 url_launcher 调用 launch
方法包装:
launch("tel://214324234");
这是完整的代码:
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.2
https://stackoverflow.com/questions/45523370/