How to make a phone call from a flutter app

后端 未结 7 887
迷失自我
迷失自我 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 00:59

    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 {
          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:[
                    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);
                      },
                    )
                  ]
                ),
              ),
            );
          }
        }
    

提交回复
热议问题