Commit 1ecb531
authored
[shared_preferences]Fix : SetState returning future (#8398)
This pull request includes a change to the `SharedPreferencesDemoState` class in the `main.dart` file. The change improves the way the external counter value is fetched and updated in the state.
* [`packages/shared_preferences/shared_preferences/example/lib/main.dart`](diffhunk://#diff-6e8eaf30aa7259bf259f36e9c2057d82498b436c508f202521b4f8808788c15bL59-R61): Refactored the `_getExternalCounter` method to fetch the external counter value before calling `setState`, ensuring that asynchronous operations are handled correctly.
The issue was :
```
FlutterError (setState() callback argument returned a Future.
The setState() method on SharedPreferencesDemoState#1acdd(lifecycle state: created) was called with a closure or method that returned a Future. Maybe it is marked as "async".
Instead of performing asynchronous work inside a call to setState(), first execute the work (without updating the widget state), and then synchronously update the state inside a call to setState().)
```1 parent 1023443 commit 1ecb531
File tree
3 files changed
+8
-3
lines changed3 files changed
+8
-3
lines changedLines changed: 4 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
1 | 5 | | |
2 | 6 | | |
3 | 7 | | |
| |||
Lines changed: 3 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
59 | 59 | | |
60 | 60 | | |
61 | 61 | | |
62 | | - | |
63 | | - | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
64 | 65 | | |
65 | 66 | | |
66 | 67 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
| 6 | + | |
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| |||
0 commit comments