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
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 {
@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)