You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何解决:plugins.flutter.io/shared_preferences通道getAll方法无实现异常

Flutter SharedPreferences MissingPluginException 问题求助

我被这个问题困扰近半天,尝试使用Flutter的SharedPreferences包存储键值对。当执行await SharedPreferences.getInstance()获取实例时,应用可正常构建运行,但执行到该行代码时崩溃,抛出错误:

MissingPluginException (MissingPluginException(No implementation found for method getAll on channel plugins.flutter.io/shared_preferences))

我查阅过多个StackOverflow帖子及GitHub Issue,但均未解决问题:

  • MissingPluginException(No implementation found for method getAll on channel plugins.flutter.io/shared_preferences) while getting FCM in background
  • Unhandled Exception: MissingPluginException(No implementation found for method getAll on channel plugins.flutter.io/ for many packages on Flutter
  • Flutter Test: MissingPluginException(No implementation found for method getAll on channel plugins.flutter.io/shared_preferences)
  • Flutter MissingPluginException(No implementation found for method getAll on channel ...) in release app
  • Unhandled Exception: MissingPluginException(No implementation found for method flutterToWatch on channel it.example.watch)
  • Flutter: Unhandled exception: MissingPluginException(No implementation found for method getAll on channel plugins.flutter.io/shared_preferences)
  • GitHub Issue #98473

我尝试了以下方法,均无效果:

  • 执行flutter pub get
  • 添加注册代码:io.flutter.plugins.sharedpreferences.SharedPreferencesPlugin.registerWith(registry.registrarFor("io.flutter.plugins.sharedpreferences.SharedPreferencesPlugin"));
  • 针对iOS平台添加:SharedPreferencesIOS.registerWith();
  • 使用flutter_isolate包
  • 执行flutter clean && flutter pub get
  • 添加模拟初始化代码:SharedPreferences.setMockInitialValues({});

执行上述操作后,我重启了编辑器(VS Code),甚至安装带Flutter扩展的Android Studio尝试,依旧无效。也试过从命令行运行,仍返回相同错误,还重启了电脑、卸载重装Flutter和Dart,但问题仍存在。

请问我还遗漏了哪些解决步骤?


内容的提问来源于stack exchange,提问作者Awesomeplayer165

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.16 06:05:19