How to make a phone call from a flutter app

后端 未结 7 900
迷失自我
迷失自我 2020-12-03 00:39

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

7条回答
  •  情话喂你
    2020-12-03 01:15

    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

提交回复
热议问题