84

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 GitHub flutter repo: https://github.com/flutter/flutter/issues/4856

But this doesn't work for me. Is this Function still in Flutter and in which package? Or is there a better option to do a phone call from my app?

Paresh Mangukiya
  • 37,512
  • 17
  • 201
  • 182
Lukas Kirner
  • 3,469
  • 5
  • 21
  • 29
  • 1
    Does this answer your question? [How can I dial the phone from Flutter?](https://stackoverflow.com/questions/43149073/how-can-i-dial-the-phone-from-flutter) – iDecode Jan 13 '21 at 09:12
  • Check Latest Answer: https://stackoverflow.com/a/67722228/1318946 – Pratik Butani May 27 '21 at 12:35

11 Answers11

167

Call the launch method from url_launcher package:

launch("tel://214324234");

Here's the complete code:

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 and then use

import 'package:url_launcher/url_launcher.dart' as UrlLauncher;
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
Saeed
  • 1,179
  • 1
  • 14
  • 23
German Saprykin
  • 6,071
  • 2
  • 26
  • 26
  • 1
    And how are you using that in the code? My Problem is that UrlLauncher can't be found. – Lukas Kirner Aug 05 '17 at 16:05
  • 3
    U need to add 'dependencies: url_launcher: "^3.0.0 " in pubspec.yaml and run Package upgrade – Victor Tong Mar 27 '18 at 06:16
  • @GermanSaprykin I am getting missing plugin exception even though i added url_launcher: ^4.0.3 in pubspec.yaml file – Pritish Jan 09 '19 at 13:02
  • 2
    @Nudge Don’t forget to install packages via “flutter pub get” and relaunch the app – German Saprykin Jan 10 '19 at 14:13
  • @GermanSaprykin I had already installed the package and did package get, but when i completely closed the app and restarted the app then it started working – Pritish Jan 11 '19 at 05:23
  • Flutter supports hot reloading for dart code, but not native. So an app has to be relaunched for new plugins – German Saprykin Jan 11 '19 at 12:11
  • 3
    According to https://pub.dartlang.org/packages/url_launcher#-readme-tab- , the phone call url should be tel:, e.g. tel:+1 555 010 999 – Chandler Jan 14 '19 at 01:28
  • doubt, i have to make direct call instead landing in the phone keypad....!! is there any options like that???? – kriss Oct 21 '19 at 13:24
14

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}'),
piet.t
  • 11,400
  • 21
  • 42
  • 50
GirlWhoCode
  • 558
  • 3
  • 12
  • 1
    I am guessing this wont connect a call but redirect you to the inbuilt phone dialer app with the phone number is't there a way to actually make a call on click of button from the flutter app itself – Mahesh Jamdade Sep 25 '19 at 05:46
  • i dont think that there is a way. – GirlWhoCode Sep 25 '19 at 08:55
  • what about the app called truecaller I think it does that right?ofcourse it must have not been built in flutter but some kind of platform channel code could help – Mahesh Jamdade Sep 26 '19 at 03:46
13

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}'));
},

enter image description here

Paresh Mangukiya
  • 37,512
  • 17
  • 201
  • 182
5

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);
                  },
                )
              ]
            ),
          ),
        );
      }
    }
Yeimer
  • 67
  • 1
  • 8
4

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:

  1. pubspec.yaml add package:

    intent:

  2. 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)

Community
  • 1
  • 1
Kenneth Li
  • 1,395
  • 9
  • 19
4

url_launcher is universal package for launching url, dialing number and sending mail.

  1. Add url_launcher: ^5.5.2 to pubspec.yaml file and run flutter pub get
  2. Import package import 'package:url_launcher/url_launcher.dart';
  3. Define function:
void launchUrl(String url) async {
  if (await canLaunch(url)) {
    launch(url);
  } else {
    throw "Could not launch $url";
  }
}
  1. Call your universal function for different purposes:
//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"); 
Kerim Amanov
  • 203
  • 2
  • 13
3

To launch the device's dialer, the following code can also be used with exception handling:

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");
  }
}
flutternoob
  • 136
  • 1
  • 6
2

Just url_launcher: ^ latest Version in Pubspec.yamal

Note: Before Pub get or Upgrade delete Pubspec.lock some time it gives unwanted problems.

Import package import 'package: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"); 
BC TUBE
  • 577
  • 4
  • 10
2

If you using url_launcher and your phone number have plus symbol like "+1111111111" for ios you should use Uri class

final Uri phoneUrl = Uri(
  scheme: 'tel',
  path: '+11111111111',
);

if (await canLaunch(phoneUrl.toString())) {
  await launch(phoneUrl.toString());
} else {
  throw "Can't phone that number.";
}
Lomski
  • 320
  • 3
  • 7
1

You can call directly by this package flutter_phone_direct_caller

Create a function and pass the mobile number value :

  _callNumber(String mobile) async {
     await FlutterPhoneDirectCaller.callNumber(mobile);
  }
Abir Ahsan
  • 1,776
  • 15
  • 31
0

You can do it by two ways:-

  • url_launcher package will be used to implement phone call using the default app of your mobile phone. This package will auto direct the phone to the default phone call making app and open the dialer screen to make the call.

  • flutter_phone_direct_caller package is not the best package but we can implement direct phone calls directly from our phone without the intermediate dialer.

Install the following dependencies inside your pubspec.yaml file:

dependencies:
  flutter:
    sdk: flutter
  cupertino_icons: ^1.0.0
  flutter_phone_direct_caller: ^1.0.1
  url_launcher: ^5.7.10

Making Phone Calls using the "flutter_phone_direct_caller" : plugin To implement the phone call using this plugin is really very easy. This package provides us FlutterPhoneDirectCaller class that provides us callNumber() method that takes a phone number.

_callNumber(String phoneNumber) async {
 String number = phoneNumber;
 await FlutterPhoneDirectCaller.callNumber(number);
}

You can implement it in your button as follows

RaisedButton(
  child: Text("Call"),
  onPressed: () {
    _callNumber(textEditingController.text);
  },

)

Making Phone Calls using the "url_launcher": plugin This package provides us launch(URL) method that takes an URL with schema. Scheme is very essential as it directs the URL. In the case of phone calls, we use ‘tel:’ schema.

_launchPhoneURL(String phoneNumber) async {
  String url = 'tel:' + phoneNumber;
  if (await canLaunch(url)) {
    await launch(url);
  } else {
    throw 'Could not launch $url';
  }
}

and to raised button:-

RaisedButton(
  child: Text("Call"),
  onPressed: () {
    _launchPhoneURL(textEditingController.text);
  },
)

IF you need advanced features you can use "flutter_voip_kit", it is very new library, I have also not used it but it looks promising at first galance..