Sky24n/flustars

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

chenyanbin-dkhs opened this issue · 1 comments

Flutter 1.10.14-pre.12
Dart 2.6.0

errors:

[VERBOSE-2:ui_dart_state.cc(148)] Unhandled Exception: MissingPluginException(No implementation found for method getAll on channel plugins.flutter.io/shared_preferences)
#0      MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:319:7)
<asynchronous suspension>
#1      MethodChannel.invokeMapMethod (package:flutter/src/services/platform_channel.dart:349:48)
<asynchronous suspension>
#2      SharedPreferences._getSharedPreferencesMap (package:shared_preferences/shared_preferences.dart:158:25)
<asynchronous suspension>
#3      SharedPreferences.getInstance (package:shared_preferences/shared_preferences.dart:25:17)
<asynchronous suspension>
#4      SpUtil._init (package:flustars/src/sp_util.dart:40:38)
<asynchronous suspension>
#5      SpUtil.getInstance.<anonymous closure> (package:flustars/src/sp_util.dart:29:27)
<asynchronous suspension>
#6      BasicLock.synchronized (package:synchronized/src/basic_lock.dart:31:26)
<asynchronous suspension>
#7      SpUtil.getInstance (pac<…>

解决方法:

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

await SpUtil.getInstance();

//  todo more

不需要的,都使用很久了,没有问题的