MissingPluginException(未找到方法切换通道唤醒锁的实现) - Flutter 唤醒锁

MissingPluginException(No implementation found for method toggle on channel wakelock) - Flutter wakelock

我在使用唤醒锁时在调试控制台中收到此错误:

E/flutter (17630): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: MissingPluginException(No implementation found for method toggle on channel wakelock)

这是我的代码:

import 'package:wakelock/wakelock.dart';

class _MyHomePageState extends State<MyHomePage> {
bool on = true;
// The following statement enables the wakelock.
 void initState() {
    super.initState();
    Wakelock.toggle(on: on);
}

我也确实在我的 AndroidManifest.xml <uses-permission android:name="android.permission.WAKE_LOCK" />

中添加了这个

这在依赖项中:wakelock: ^0.1.4+2

我该如何解决这个问题?

停止调试器,在终端中执行 'flutter clean' 并重新启动应用程序。

我解决了这个问题。请确保您已更新 flutter 和 dart,因为看起来该插件在某些版本中存在错误。我将 flutter 更新到 1.20.3(dart 2.9.2),现在一切正常。