Skip to content
This repository was archived by the owner on Jul 16, 2023. It is now read-only.

Commit f97a9ea

Browse files
committed
fix: reword documentation
1 parent a5f9d95 commit f97a9ea

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

website/docs/rules/flutter/avoid-async-setstate.mdx

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ that the widget has been unmounted needs to be checked before calling [`setState
1111
Consider storing Futures directly in your state and use [`FutureBuilder`](https://api.flutter.dev/flutter/widgets/FutureBuilder-class.html)
1212
to unwrap them.
1313

14-
If not possible, you can also check for [`mounted`] to only update state when the widget is still mounted. However, an effective fix usually
14+
If this is not possible, you can also check for [`mounted`] to only update state when the widget is still mounted. However, an effective fix usually
1515
does not make use of [`mounted`], but rather revolves around refactoring your states.
1616

1717
:::info
@@ -68,6 +68,29 @@ class _MyWidgetState extends State<MyWidget> {
6868

6969
**✅ Good:**
7070

71+
```dart
72+
class _MyWidgetState extends State<MyWidget> {
73+
String message;
74+
75+
@override
76+
Widget build(BuildContext context) {
77+
return Button(
78+
onPressed: () async {
79+
String fromServer = await fetch(...);
80+
if (mounted) {
81+
setState(() {
82+
message = fromServer;
83+
});
84+
}
85+
},
86+
child: Text(message),
87+
);
88+
}
89+
}
90+
```
91+
92+
**✅ Good:**
93+
7194
```dart
7295
class _MyWidgetState extends State<MyWidget> {
7396
Future<String> message;

0 commit comments

Comments
 (0)