如何解决:plugins.flutter.io/shared_preferences通道getAll方法无实现异常
我被这个问题困扰近半天,尝试使用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
相关产品推荐
相关产品推荐

