试图从iOS拨打电话

时间:2020-08-14 13:34:22

标签: flutter dart

我正在尝试使用url_launcher,以便通过按钮将我带到电话的拨号器以进行呼叫。在android中,它可以完美运行,但是当我在IOS中运行时,它不起作用,它什么也不做,我不知道代码中是否缺少某些内容,感谢您的帮助

这是我正在使用的代码:

import 'dart:io';

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

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,
       
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      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> {
  final String _phoneNumber = '318654378';

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: RaisedButton(
            child: Text('Call Number'),
            onPressed: () {
              if (Platform.isAndroid) {
                // _callNumber();
                launch('tel://$_phoneNumber');
              } else if (Platform.isIOS) {
                launch('tel://$_phoneNumber');
              }
            }),
      ),

    );
  }

}

知道发生了什么事

0 个答案:

没有答案