我尝试从我的Flutter应用程序拨打电话.使用以下代码:
- UrlLauncher.launch('tel: xxxxxxxx');
我在github flutter repo:https://github.com/flutter/flutter/issues/4856上找到了这个函数
但这对我不起作用.这个功能仍然在颤动和哪个包中?或者有更好的选择从我的应用程序拨打电话?
解决方法
我尝试在Android / iOS这次发布(“tel:// 214324234”),它运作良好.
您需要安装包 url_launcher并导入它
您需要安装包 url_launcher并导入它
- 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(),);
- }
你也可以导入它导入’package:url_launcher / url_launcher.dart’作为UrlLauncher;然后使用UrlLauncher.launch(“tel:// 21213123123”)
请确保在pubspec.yaml文件的dependencies部分中包含一个条目:url_launcher:^ 1.0.2