E/flutter (11319): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: MissingPluginEx

SharedPreferences 使用报错,如下:

E/flutter (11319): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: MissingPluginException(No implementation found for method getAll on channel plugins.flutter.io/shared_preferences)

我用的版本是

shared_preferences: ^2.0.8

需要在 main 方法添加:

void main() {
  SharedPreferences.setMockInitialValues({});
  runApp(MyApp());
}

你可能感兴趣的:(flutter开发,flutter,ui)