If you're using shared_preferences 0.2.4 and above, use setMockInitialValues
:
SharedPreferences.setMockInitialValues({}); // set initial values here if desired
For earlier versions you can do it manually:
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;
});
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…