如何在 flutter 中重定向到 iOS 上的 whatsapp

how to redirect to whatsapp on iOS in flutter

我制作了一个带有重定向到 whatsapp 按钮的应用程序,问题是在 Android 中如果它有效而不是在 iOS 中,我已经完成了使用常规方法,我认为您必须将某些内容放入 iOS 文件中,但我不知道那是

谢谢。

ListTile(
    leading:  Icon(FontAwesomeIcons.headset,color: Colors.black,),
    title: Text('Centro de ayuda '),
    onTap: () async => await launch("https://wa.me/${numero}?text=Hola mi nombre es "+prefs.name+' y necesito ayuda con mi orden de Timugo')            
)

您可以添加 Flutter 启动 WhatsApp。

安装: 首先,在 pubspec.yaml 文件中添加 flutter_launch_whatsapp 作为依赖项。

在 iOS 添加以下内容 Info.plist :

<key>LSApplicationQueriesSchemes</key>
<array>
  <string>whatsapp</string>
</array>

示例:

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

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

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => new _MyAppState();
}

class _MyAppState extends State<MyApp> {

  @override
  initState() {
    super.initState();
  }

  void whatsAppOpen() async {
    await FlutterLaunch.launchWathsApp(phone: "5534992016545", message: "Hello");
  }

  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      home: new Scaffold(
        appBar: new AppBar(
          title: new Text('Plugin example app'),
        ),
        body: new Center(
          child: FlatButton(
            child: Text("Open WhatsApp"),
            onPressed: () {
              whatsAppOpen();
            },
          )
        ),
      ),
    );
  }
}

以上参考来自: https://pub.dev/packages/flutter_launch

您可以试试下面的代码:

var whatsappUrl ="whatsapp://send?phone=$phone";
await canLaunch(whatsappUrl)? launch(whatsappUrl):print("open whatsapp app link or do a snackbar with notification that there is no whatsapp installed");