'How can I make a direct PHONE CALL in Flutter
I need to make a direct Phone Call in flutter but it's just opening the Phone app dialer.
No direct phone call is made.
In fact, I also tried with url_launcher package for this task but am getting the same result.
_launchURL() async {
SimplePermissions.requestPermission(Permission.CallPhone)
.then((state) async {
if (state == PermissionStatus.authorized) {
String a = Uri.encodeFull("#");
String url = 'tel:*123' + a;
if (await canLaunch(url)) {
await launch(url);
} else {
throw 'Could not launch $url';
}
}
});}
Has anyone solved this before?
Solution 1:[1]
You need to use URL encoding for special character.
Like this:
launch("tel:" + Uri.encodeComponent('*123#'));
Solution 2:[2]
I made a plugin called flutter_phone_direct_caller exactly for this purpose.
You can use it like this:
import 'package:flutter/material.dart';
import 'package:flutter_phone_direct_caller/flutter_phone_direct_caller.dart';
void main() {
runApp(Scaffold(
body: Center(
child: RaisedButton(
onPressed: _callNumber,
child: Text('Call Number'),
),
),
));
}
_callNumber() async{
const number = '08592119XXXX'; //set the number here
bool res = await FlutterPhoneDirectCaller.callNumber(number);
}
Hopefully it can help someone.
Solution 3:[3]
Add these packages to your dependencies:
android_intent_plus: ^2.0.0
permission_handler: ^8.1.4+2
Import them in your .dart file:
import 'package:android_intent_plus/android_intent.dart';
import 'package:permission_handler/permission_handler.dart';
Request for phone call permission in your main() function:
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Permission.phone.request();
runApp(const MyApp());
}
And finally you can make direct phone calls like this:
AndroidIntent intent = const AndroidIntent(
action: 'android.intent.action.CALL',
data: 'tel:2125551212',
);
await intent.launch();
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | davidrm90 |
| Solution 2 | Yanis Alfian |
| Solution 3 | Ercan Tomaç |
