I try to make a phone call from my Flutter app. With the following code:
UrlLauncher.launch(\'tel: xxxxxxxx\');
I found this Function on the
This worked for me
use this plugin
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:flutter_phone_direct_caller/flutter_phone_direct_caller.dart';
void main() => runApp(new MyApp());
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => new _MyAppState();
}
class _MyAppState extends State<MyApp> {
TextEditingController _numberCtrl = new TextEditingController();
@override
void initState() {
super.initState();
_numberCtrl.text = "085921191121";
}
@override
Widget build(BuildContext context) {
return new MaterialApp(
home: new Scaffold(
appBar: new AppBar(
title: const Text('Plugin example app'),
),
body: new Column(
children:<Widget>[
Padding(
padding: EdgeInsets.all(8.0),
child: TextField(
controller: _numberCtrl,
decoration: InputDecoration(
labelText: "Phone Number"
),
keyboardType: TextInputType.number,
),
),
RaisedButton(
child: Text("Test Call"),
onPressed: () async{
FlutterPhoneDirectCaller.callNumber(_numberCtrl.text);
},
)
]
),
),
);
}
}
You should add this in your pubspec.yaml => url_launcher: ^5.0.2 then you click Packages get .
in your code you add the import : import 'package:url_launcher/url_launcher.dart' as UrlLauncher; Hope it works =)
import 'package:url_launcher/url_launcher.dart' as UrlLauncher;
UrlLauncher.launch('tel:+${p.phone.toString()}')
//if mail
UrlLauncher.launch('mailto:${p.email}'),
url_launcher is universal package for launching url, dialing number and sending mail.
url_launcher: ^5.5.2
to pubspec.yaml file and run flutter pub get
import 'package:url_launcher/url_launcher.dart';
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");
I am able to make a phone call by bringing up the system phone app and CONNECT A CALL:
Here's what you need to do:
pubspec.yaml add package:
intent:
main.dart:
import 'package:flutter/material.dart';
import 'package:intent/intent.dart' as android_intent;
import 'package:intent/action.dart' as android_action;
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return (Scaffold(
body: Center(
child: RaisedButton(
onPressed: _launchURL,
child: Text('Dial a number'),
)
),
));
}
}
_launchURL() async {
// Replace 12345678 with your tel. no.
android_intent.Intent()
..setAction(android_action.Action.ACTION_CALL)
..setData(Uri(scheme: "tel", path: "12345678"))
..startActivity().catchError((e) => print(e));
}
Then, after running this app and click the "Dial a number", the System Phone App will bring up and make a call. (Unlike url_launcher, you don't need to press the Green Call button in the System Phone App)
If you are not getting any action on the click of the button, So this is happening because of this. So this is happening because you might not have add tel:// before the number.
Do it this way
Full code is given below
launch(('tel://${mobile_no}')); //launch(('tel://99999xxxxx'));
1) in pubspec.yaml
dependencies:
flutter:
sdk: flutter
url_launcher: ^5.4.10
2) Import wherever you want to use
import 'package:url_launcher/url_launcher.dart';
3) final you call
onPressed: () {
launch(('tel://${item.mobile_no}'));
},
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(),
);
}
Also you can import it import 'package:url_launcher/url_launcher.dart' as UrlLauncher;
and then use UrlLauncher.launch("tel://21213123123")
Be sure to include an entry for it in the pubspec.yaml file, in the dependencies section: url_launcher: ^1.0.2