Flutter 如何从Flatter应用程序拨打电话
我尝试从我的Flitter应用程序打电话。使用以下代码:Flutter 如何从Flatter应用程序拨打电话,flutter,dart,phone-call,Flutter,Dart,Phone Call,我尝试从我的Flitter应用程序打电话。使用以下代码: UrlLauncher.launch('tel: xxxxxxxx'); 我在GitHub Flatter repo上找到了这个函数: 但这对我不起作用。该功能是否仍处于颤振状态?在哪个软件包中?或者是否有更好的选择从我的应用程序拨打电话?从软件包中调用启动方法: launch(“tel://214324234"); 以下是完整的代码: import 'package:flutter/material.dart'; import '
UrlLauncher.launch('tel: xxxxxxxx');
我在GitHub Flatter repo上找到了这个函数:
但这对我不起作用。该功能是否仍处于颤振状态?在哪个软件包中?或者是否有更好的选择从我的应用程序拨打电话?从软件包中调用
启动
方法:
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(),
);
}
您还可以将其导入“包:url\u launcher/url\u launcher.dart”作为UrlLauncher然后使用UrlLauncher.launch(“tel://21213123123“”
请确保在pubspec.yaml文件的“依赖项”部分包含一个条目:
url\u启动器:^1.0.2
您应该将其添加到您的pubspec.yaml=>url\u启动器:^5.0.2,然后单击“获取”
在代码中添加import:import'package:url\u launcher/url\u launcher.dart'作为UrlLauncher;
希望它能起作用=)
我可以通过打开系统电话应用程序拨打电话并连接电话: 以下是您需要做的:
导入“包装:颤振/材料.省道”;
将“package:intent/intent.dart”导入为android\u intent;
将“package:intent/action.dart”导入为android_action;
void main()=>runApp(MyApp());
类MyApp扩展了无状态小部件{
//此小部件是应用程序的根。
@凌驾
小部件构建(构建上下文){
返回材料PP(
标题:“颤振演示”,
主题:主题数据(
主样本:颜色。蓝色,
),
主页:MyHomePage(标题:“颤振演示主页”),
);
}
}
类MyHomePage扩展StatefulWidget{
MyHomePage({Key,this.title}):超级(Key:Key);
最后的字符串标题;
@凌驾
_MyHomePageState createState()=>\u MyHomePageState();
}
类_MyHomePageState扩展状态{
@凌驾
小部件构建(构建上下文){
返回(脚手架)(
正文:中(
孩子:升起按钮(
onPressed:_launchURL,
子项:文本(“拨打号码”),
)
),
));
}
}
_启动URL()异步{
//将12345678替换为您的电话号码。
android_intent.intent()
..setAction(android_action.action.action_调用)
..设置数据(Uri(方案:“电话”,路径:“12345678”))
…startActivity().catchError((e)=>print(e));
}
然后,运行此应用程序并单击“拨号”后,系统电话应用程序将弹出并拨打电话。(与url_launcher不同,您不需要按下系统电话应用程序中的绿色呼叫按钮)如果您在点击按钮时没有收到任何操作,则会发生这种情况。发生这种情况是因为您可能没有在号码前添加电话:// 这样做 完整代码如下所示
launch(('tel://${mobile_no}')); //launch(('tel://99999xxxxx'));
1)在pubspec.yaml中
dependencies:
flutter:
sdk: flutter
url_launcher: ^5.4.10
2)在您想使用的任何位置导入
import 'package:url_launcher/url_launcher.dart';
3)你最后的电话
onPressed: () {
launch(('tel://${item.mobile_no}'));
},
这对我很有效
使用
导入“包装:颤振/材料.省道”;
导入“dart:async”;
导入“包:flifter/services.dart”;
导入“package:flatter_phone_direct_caller/flatter_phone_direct_caller.dart”;
void main()=>runApp(新的MyApp());
类MyApp扩展了StatefulWidget{
@凌驾
_MyAppState createState()=>new_MyAppState();
}
类MyAppState扩展了状态{
TextEditingController_numberCtrl=新的TextEditingController();
@凌驾
void initState(){
super.initState();
_numberCtrl.text=“085921191121”;
}
@凌驾
小部件构建(构建上下文){
返回新材料PP(
家:新脚手架(
appBar:新的appBar(
标题:const Text(“插件示例应用程序”),
),
正文:新栏目(
儿童:[
填充物(
填充:边缘设置。全部(8.0),
孩子:TextField(
控制器:_numberCtrl,
装饰:输入装饰(
labelText:“电话号码”
),
键盘类型:TextInputType.number,
),
),
升起的按钮(
子项:文本(“测试调用”),
onPressed:()异步{
flatterPhoneDirectCaller.callNumber(_numberCtrl.text);
},
)
]
),
),
);
}
}
是用于启动url、拨打号码和发送邮件的通用软件包
url\u启动器:^5.5.2
添加到pubspec.yaml文件并运行flatter pub get
Import'package:url_launcher/url_launcher.dart'代码>
只是Pubspec.yamal中的
url\u启动器:^最新版本
注意:在发布获取或升级之前,删除Pubspec.lock会出现一些不必要的问题
导入包导入“包:url_launcher/url_launcher.dart”
//for launching URL
launchUrl("HTTP://website.com");
// for dial phone number
launchUrl("tel:+91963852741");
// for sending email
launchUrl("mailto:mail@gmail.com?subject=Meeting&body=Can we meet via Google Meet");
如果您使用的是url\u启动器,并且您的手机号码有“+1111111111”等加号,您应该使用Uri类
final Uri phoneUrl = Uri(
scheme: 'tel',
path: '+11111111111',
);
if (await canLaunch(phoneUrl.toString())) {
await launch(phoneUrl.toString());
} else {
throw "Can't phone that number.";
}
你可以用这个包裹直接打电话 创建函数并传递手机号码值:
要启动设备的拨号程序,以下代码也可用于异常处理:
Future<void> launchPhoneDialer(String contactNumber) async {
final Uri _phoneUri = Uri(
scheme: "tel",
path: contactNumber
);
try {
if (await canLaunch(_phoneUri.toString()))
await launch(_phoneUri.toString());
} catch (error) {
throw("Cannot dial");
}
}
Future launchPhoneDialer(字符串联系人号码)异步{
最终Uri _phoneUri=Uri(
计划:"电话,,
路径:联系人号码
);
试一试{
if(等待canLaunch(_phoneUri.toString()))
等待启动(_phoneUri.toString());
}捕获(错误){
抛出(“无法拨号”);
}
}
和ho
void launchUrl(String url) async {
if (await canLaunch(url)) {
launch(url);
} else {
throw "Could not launch $url";
}
}
//for launching url
launchUrl("HTTP://example.com");
// for dial phone number
launchUrl("tel:+99364921507");
// for sending email
launchUrl("mailto:zehinz@gmail.com?subject=Meeting&body=Can we meet via Google Meet");
//for launching URL
launchUrl("HTTP://website.com");
// for dial phone number
launchUrl("tel:+91963852741");
// for sending email
launchUrl("mailto:mail@gmail.com?subject=Meeting&body=Can we meet via Google Meet");
final Uri phoneUrl = Uri(
scheme: 'tel',
path: '+11111111111',
);
if (await canLaunch(phoneUrl.toString())) {
await launch(phoneUrl.toString());
} else {
throw "Can't phone that number.";
}
_callNumber(String mobile) async {
await FlutterPhoneDirectCaller.callNumber(mobile);
}
Future<void> launchPhoneDialer(String contactNumber) async {
final Uri _phoneUri = Uri(
scheme: "tel",
path: contactNumber
);
try {
if (await canLaunch(_phoneUri.toString()))
await launch(_phoneUri.toString());
} catch (error) {
throw("Cannot dial");
}
}