How to make a phone call from Flutter app

Its very easy to start initiate a call from your flutter app. That is, a phone number can be routed to the phone’s call app to start a phone call. very easy!

Just like the launch URL article, we’ll be using the same url_launcher package, only chaning a few stuffs.

in your pubscpec.yaml, add

url_launcher: ^4.1.0

Create a new dart file and paste this code:

import 'package:url_launcher/url_launcher.dart';
import 'package:flutter/material.dart';

class CallPhone extends StatelessWidget {
  final String phone = 'tel:+2347012345678';

  _callPhone() async {
    if (await canLaunch(phone)) {
      await launch(phone);
    } else {
      throw 'Could not Call Phone';
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('Call Phone from App Example')),
      body: Center(
          child: RaisedButton(
        onPressed: _callPhone,
        child: Text('Call Phone'),
        color: Colors.red,
      )),
    );
  }
}

In your main.dart file, paste this code:

void main() => runApp(new MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      debugShowCheckedModeBanner: false,
      title: 'Flutter Code Snippets',
      theme: new ThemeData(primarySwatch: Colors.red),
      home: new CallPhone(),
    );
  }
}

If you have any questions or suggestions kindly use the comment box or you can contact us directly through our contact page below.

Add a Comment