You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
My guess is that it cannot be read, and the result of each read is null. So the result of counter = (values['counter'] as int? ?? 0) + 1 is 1, write 1 again.
I located the problem, which is _defaultPrefix. The definitions of key between getAllWithParameters and setValue are not consistent. I can temporarily use final Map<String, Object> values = await prefs.getAllWithPrefix(""); to solve the problem.
i run main.dart, always "Button tapped 1 time", when i restart App, it become "0 times".I just added some printing:
Future _incrementCounter() async {
final Map<String, Object> values = await prefs.getAll();
final int counter = (values['counter'] as int? ?? 0) + 1;
print('_incrementCounter:values:$values');
setState(() {
_counter = prefs.setValue('Int', 'counter', counter).then((bool success) {
print('_incrementCounter:success:$success');
return counter;
});
});
}
No matter how many times i click,output always:
_incrementCounter:values:{}
_incrementCounter:success:true
...
No error message is reported。
so,where might the problem occur?
Looking forward to your reply,
thanks.
The text was updated successfully, but these errors were encountered: