【问题标题】:How to launch whatsapp video call through a flutter app?如何通过 Flutter 应用启动 whatsapp 视频通话?
【发布时间】:2021-09-19 12:03:32
【问题描述】:

我们可以通过点击 Flutter 应用中的按钮进行 WhatsApp 视频通话吗?

【问题讨论】:

    标签: flutter dart whatsapp videocall


    【解决方案1】:

    您可以参考WhatsApp官网并使用通用链接(see more)。例如,您可以使用此 URL 发送sample text

    const url = "https://wa.me/<number>?text=SAMPLE TEXT";
    

    如果您尝试打开此 URL 并且用户在他/她的手机中有 WhatsApp,则此消息将在此应用程序中打开。您可以用给定的关键字替换text 来拨打电话。

    【讨论】:

      【解决方案2】:

      然后添加此依赖项:

      dependencies:
        call_with_whatsapp: ^0.0.1
      

      然后:

      import 'package:flutter/cupertino.dart';
      import 'package:flutter/material.dart';
      import 'dart:async';
      
      import 'package:flutter/services.dart';
      import 'package:call_with_whatsapp/call_with_whatsapp.dart';
      
      void main() => runApp(MyApp());
      
      class MyApp extends StatefulWidget {
        @override
        _MyAppState createState() => _MyAppState();
      }
      
      class _MyAppState extends State<MyApp> {
      
        @override
        void initState() {
          super.initState();
        }
      
        void _requestPermission() {
          CallWithWhatsapp.requestPermissions().then((x){
            print("success");
          }).catchError((e){
            print(e);
          });
        }
      
        void _openStore() {
          CallWithWhatsapp.openInPlayStore().then((x){
            print("success");
          }).catchError((e){
            print(e);
          });
        }
      
        void _initiateCall() {
          CallWithWhatsapp.initiateCall("01753230535").then((x){
            print("success");
          }).catchError((e){
            print(e);
          });
        }
      
        void _createNewContact() {
          CallWithWhatsapp.createContact("AAAAA AAAA", "0111111").then((x){
            print("success");
          }).catchError((e){
            print(e);
          });
        }
      
        @override
        Widget build(BuildContext context) {
          return MaterialApp(
            home: Scaffold(
              appBar: AppBar(
                title: const Text('Plugin example app'),
              ),
              body:SafeArea(
                child: Center(
                  child: Column(
                    mainAxisAlignment: MainAxisAlignment.center,
                    crossAxisAlignment: CrossAxisAlignment.center,
                    children: <Widget>[
                      RaisedButton(
                        onPressed: _requestPermission,
                        child: Text(
                          "Request permission",
                        ),
                      ),
                      RaisedButton(
                        onPressed: _openStore,
                        child: Text(
                          "Open In Playstore",
                        ),
                      ),
                      RaisedButton(
                        onPressed: _initiateCall,
                        child: Text(
                          "Initiate Call",
                        ),
                      ),
                      RaisedButton(
                        onPressed: _createNewContact,
                        child: Text(
                          "Create contact",
                        ),
                      ),
                    ],
                  ),
                ),
              ),
            ),
          );
        }
      
      
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2022-12-28
        • 1970-01-01
        • 2019-03-23
        • 1970-01-01
        • 1970-01-01
        • 2020-02-19
        • 1970-01-01
        • 2020-05-07
        相关资源
        最近更新 更多