【问题标题】:Error: MissingPluginException(No implementation found for method share on channel plugins.flutter.io/share)错误:MissingPluginException(在通道 plugins.flutter.io/share 上找不到方法共享的实现)
【发布时间】:2021-12-30 11:02:23
【问题描述】:

今天我在测试我的应用程序的新功能时遇到了这个错误

    at Object.throw_ [as throw] (http://localhost:17968/dart_sdk.js:5063:11)
    at MethodChannel._invokeMethod (http://localhost:17968/packages/flutter/src/services/restoration.dart.lib.js:1555:21)
    at _invokeMethod.next (<anonymous>)
    at http://localhost:17968/dart_sdk.js:40192:33
    at _RootZone.runUnary (http://localhost:17968/dart_sdk.js:40062:59)
    at _FutureListener.thenAwait.handleValue (http://localhost:17968/dart_sdk.js:34983:29)
    at handleValueCallback (http://localhost:17968/dart_sdk.js:35551:49)
    at Function._propagateToListeners (http://localhost:17968/dart_sdk.js:35589:17)
    at _Future.new.[_completeWithValue] (http://localhost:17968/dart_sdk.js:35437:23)
    at async._AsyncCallbackEntry.new.callback (http://localhost:17968/dart_sdk.js:35458:35)
    at Object._microtaskLoop (http://localhost:17968/dart_sdk.js:40330:13)
    at _startMicrotaskLoop (http://localhost:17968/dart_sdk.js:40336:13)
    at http://localhost:17968/dart_sdk.js:35811:9

我用谷歌搜索并找到了另一个关于该问题的论坛条目。他们说出现错误,确认热重载。他们说我应该停止应用程序并重新运行它,但它并没有解决错误。代码来自教程,一切正常。 这是我的代码:

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

class DetailScreen extends StatelessWidget {

  const DetailScreen(this.title, this.done);
  final String title;
  final bool done;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: done ? Colors.green : Colors.red,
      appBar: AppBar(
        title: Text('Detail Screen'),
        backgroundColor: Colors.transparent,
      ),
      body: Padding(
        padding: EdgeInsets.symmetric(vertical: 70),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.spaceAround,
          children: <Widget>[
            Expanded(
                child: Container(
                    padding: EdgeInsets.all(20),
                    alignment: Alignment.center,
                    child: Text(
                      done ? 'Das hast du schon erledigt:' : 'Das musst du noch machen:',
                      style: TextStyle(fontSize: 20, color: Colors.white), textAlign: TextAlign.center,))
            ),
            Expanded(
                child: Container(
                    alignment: Alignment.center,
                    child: Text(title, style: TextStyle(fontSize: 50, color: Colors.white)))
            ),
            Expanded(
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceAround,
                children: <Widget>[
                  IconButton(
                    iconSize: 60,
                    onPressed: () {
                      String message;
                      if (done) {
                        message = 'Ich habe folgendes Todo erledigt: ' + title;
                      } else {
                        message = 'Das muss noch erledigt werden: ' + title;
                      }
                      Share.share(message);
                    },
                    icon: Icon(Icons.share, color: Colors.white),
                  ),
                  IconButton(
                    iconSize: 60,
                    onPressed: () => Navigator.pop(context),
                    icon: Icon(done ? Icons.check : Icons.close, color: Colors.white),
                  ),
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }
}

哦,有时 IntelliJ 会将我转发到名为“binding.dart”的类并标记completer.complete(reply);。但我不知道,它会对我说什么。我用于分享功能的包是this

【问题讨论】:

  • 强制停止正在运行的应用程序,执行flutter pub getinvalidate cache &amp; restart
  • 第二步怎么做?
  • 假设您使用的是Android Studio,请转到pubspec.yaml & 点击Pub get,如果使用的是VSCode,则使用终端中的命令。
  • 您在什么设备上运行应用程序?
  • 我使用 chrome (Web),但使用的是 Iphone X

标签: flutter dart share


【解决方案1】:

正如你所说的

我用谷歌搜索并找到了另一个关于该问题的论坛条目。他们说出现错误,确认热重载。他们说我应该停止应用程序并重新运行它,但它并没有解决错误。代码来自教程,一切正常。

不适合你尝试运行 flutter clean 和 flutter pub get

【讨论】:

  • 这对我不起作用我清理颤振并运行命令来获取酒吧。现在我在调试窗口中没有收到任何错误,但是当我单击图标时,IntelliJ 会打开一个文件名 binding.dart 并将行标记为 completer.complete(reply); 绿色。
猜你喜欢
  • 2020-12-30
  • 1970-01-01
  • 2022-08-18
  • 2023-01-23
  • 2020-10-20
  • 2021-07-18
  • 2021-04-23
  • 2020-12-09
相关资源
最近更新 更多