如果您使用的是shared_preferences 0.2.4及更高版本,请使用
setMockInitialValues:
SharedPreferences.setMockInitialValues({}); // set initial values here if desired对于早期版本,您可以手动进行操作:
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; });


