Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
877 views
in Technique[技术] by (71.8m points)

dart - How to make a phone call from a flutter app

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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 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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...