从 Flutter App 启动 Whatsapp 时出现问题

Problem launching Whatsapp from Flutter App

我正在创建一个应用程序,我需要启动 Whatsapp。我尝试了此处描述的内容:pub.dartlang.org/packages/flutter_launch 并将相同的代码粘贴到我的项目中。问题是:

What went wrong:
The Android Gradle plugin supports only Kotlin Gradle plugin version 1.2.51 and higher. Project 'flutter_launch' is using version 1.1.51.
Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
Get more help at https://help.gradle.org

这是我的代码:

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: "3381559137", 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();
            },
          )
        ),
      ),
    );
  }
}

The Android Gradle plugin supports only Kotlin Gradle plugin version 1.2.51 and higher. Project 'flutter_launch' is using version 1.1.51.

如果您正在关注此 example,则更改此问题即可解决:

buildscript {
    ext.kotlin_version = '1.1.51'
    repositories {
        google()

为此:

buildscript {
    ext.kotlin_version = '1.2.51'
    repositories {
        google()

build.gradle文件中

编辑

如您所见,thread 出现问题,他们必须重建插件。 一个人提议使用旧版本

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

使用这个 url_launcher 而不是 flutter_launch

url_launcher: 4.0.0 in pubspec.yml

import 'package:url_launcher/url_launcher.dart';

试一试,否则你可以看看如何从库中排除版本并使用你的版本,就像这个人所做的那样,但我没有测试过 replace kotlin plugin from flutter on runtime

只需更新包的版本

依赖关系:

颤振:

sdk: flutter

url_launcher:^5.1.0