首页
Preview

shared_preferences报错

  • 报错:
MissingPluginException(No implementation found for method getAll on channel plugins.flutter.io/shared_preferences)
  • 解决: shared_preferences 0.2.4及更高版本,请使用setMockInitialValues
void main() {
  SharedPreferences.setMockInitialValues({});
  runApp( MyApp());
}

更早的版本,你可以手动进行操作:

const MethodChannel('plugins.Flutter.io/shared_preferences')
  .setMockMethodCallHandler((MethodCall methodCall) async {
    if (methodCall.method == 'getAll') {
      return <String, dynamic>{}; // set initial values here if desired
    }
    return null;
  });

版权声明:本文内容由TeHub注册用户自发贡献,版权归原作者所有,TeHub社区不拥有其著作权,亦不承担相应法律责任。 如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。

点赞(0)
收藏(0)
励志猿
励志每天写一篇文章,有价值的文章,提升自我!

评论(0)

添加评论