Skip to content

Commit

Permalink
fix: example setState after dispose.
Browse files Browse the repository at this point in the history
  • Loading branch information
xuelongqy committed Jul 10, 2022
1 parent 938fab3 commit 304cf80
Show file tree
Hide file tree
Showing 20 changed files with 119 additions and 3 deletions.
11 changes: 8 additions & 3 deletions example/example.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ class _HomePageState extends State<HomePage> {
footer: const ClassicFooter(),
onRefresh: () async {
await Future.delayed(const Duration(seconds: 4));
if (!mounted) {
return;
}
setState(() {
_count = 10;
});
Expand All @@ -62,12 +65,14 @@ class _HomePageState extends State<HomePage> {
},
onLoad: () async {
await Future.delayed(const Duration(seconds: 4));
if (!mounted) {
return;
}
setState(() {
_count += 5;
});
_controller.finishLoad(_count >= 20
? IndicatorResult.noMore
: IndicatorResult.success);
_controller.finishLoad(
_count >= 20 ? IndicatorResult.noMore : IndicatorResult.success);
},
child: ListView.builder(
itemBuilder: (context, index) {
Expand Down
6 changes: 6 additions & 0 deletions example/lib/example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ class _HomePageState extends State<HomePage> {
footer: const ClassicFooter(),
onRefresh: () async {
await Future.delayed(const Duration(seconds: 4));
if (!mounted) {
return;
}
setState(() {
_count = 10;
});
Expand All @@ -61,6 +64,9 @@ class _HomePageState extends State<HomePage> {
},
onLoad: () async {
await Future.delayed(const Duration(seconds: 4));
if (!mounted) {
return;
}
setState(() {
_count += 5;
});
Expand Down
6 changes: 6 additions & 0 deletions example/lib/page/sample/carousel_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ class _CarouselPageState extends State<CarouselPage> {
controller: _controller,
onRefresh: () async {
await Future.delayed(const Duration(seconds: 2));
if (!mounted) {
return;
}
setState(() {
_count = 10;
});
Expand All @@ -50,6 +53,9 @@ class _CarouselPageState extends State<CarouselPage> {
},
onLoad: () async {
await Future.delayed(const Duration(seconds: 2));
if (!mounted) {
return;
}
setState(() {
_count += 5;
});
Expand Down
3 changes: 3 additions & 0 deletions example/lib/page/sample/chat_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,9 @@ class _ChatPageState extends State<ChatPage> {
onRefresh: () {},
onLoad: () {
return Future.delayed(const Duration(seconds: 2), () {
if (!mounted) {
return;
}
setState(() {
_messages.addAll([
MessageEntity(
Expand Down
6 changes: 6 additions & 0 deletions example/lib/page/sample/listener_header_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ class _ListenerHeaderPageState extends State<ListenerHeaderPage> {
),
onRefresh: () async {
await Future.delayed(const Duration(seconds: 2));
if (!mounted) {
return;
}
setState(() {
_count = 10;
});
Expand All @@ -53,6 +56,9 @@ class _ListenerHeaderPageState extends State<ListenerHeaderPage> {
},
onLoad: () async {
await Future.delayed(const Duration(seconds: 2));
if (!mounted) {
return;
}
setState(() {
_count += 5;
});
Expand Down
6 changes: 6 additions & 0 deletions example/lib/page/sample/page_view_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ class _PageViewPageState extends State<PageViewPage> {
),
onRefresh: () async {
await Future.delayed(const Duration(seconds: 2));
if (!mounted) {
return;
}
setState(() {
_count = 5;
});
Expand All @@ -85,6 +88,9 @@ class _PageViewPageState extends State<PageViewPage> {
},
onLoad: () async {
await Future.delayed(const Duration(seconds: 2));
if (!mounted) {
return;
}
setState(() {
_count += 5;
});
Expand Down
6 changes: 6 additions & 0 deletions example/lib/page/sample/refresh_on_start_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ class _RefreshOnStartPageState extends State<RefreshOnStartPage> {
),
onRefresh: () async {
await Future.delayed(const Duration(seconds: 2));
if (!mounted) {
return;
}
setState(() {
_count = 10;
});
Expand All @@ -72,6 +75,9 @@ class _RefreshOnStartPageState extends State<RefreshOnStartPage> {
},
onLoad: () async {
await Future.delayed(const Duration(seconds: 2));
if (!mounted) {
return;
}
setState(() {
_count += 10;
});
Expand Down
6 changes: 6 additions & 0 deletions example/lib/page/sample/secondary_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@ class _SecondaryPageState extends State<SecondaryPage> {
),
onRefresh: () async {
await Future.delayed(const Duration(seconds: 2));
if (!mounted) {
return;
}
setState(() {
_count = 10;
});
Expand All @@ -170,6 +173,9 @@ class _SecondaryPageState extends State<SecondaryPage> {
},
onLoad: () async {
await Future.delayed(const Duration(seconds: 2));
if (!mounted) {
return;
}
setState(() {
_count += 5;
});
Expand Down
6 changes: 6 additions & 0 deletions example/lib/page/sample/test_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ class _TestPageState extends State<TestPage> {
onRefresh: () async {
print('Refreshing');
await Future.delayed(const Duration(seconds: 2));
if (!mounted) {
return null;
}
setState(() {
_count = 10;
});
Expand All @@ -72,6 +75,9 @@ class _TestPageState extends State<TestPage> {
onLoad: () async {
print('Loading');
await Future.delayed(const Duration(seconds: 2));
if (!mounted) {
return null;
}
setState(() {
_count += 0;
});
Expand Down
6 changes: 6 additions & 0 deletions example/lib/page/style/bezier_circle_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ class _BezierCirclePageState extends State<BezierCirclePage> {
),
onRefresh: () async {
await Future.delayed(const Duration(seconds: 2));
if (!mounted) {
return;
}
setState(() {
_count = 10;
});
Expand All @@ -55,6 +58,9 @@ class _BezierCirclePageState extends State<BezierCirclePage> {
},
onLoad: () async {
await Future.delayed(const Duration(seconds: 2));
if (!mounted) {
return;
}
setState(() {
_count += 5;
});
Expand Down
6 changes: 6 additions & 0 deletions example/lib/page/style/bezier_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,9 @@ class _BezierPageState extends State<BezierPage> {
),
onRefresh: () async {
await Future.delayed(const Duration(seconds: 2));
if (!mounted) {
return;
}
setState(() {
_count = 10;
});
Expand All @@ -255,6 +258,9 @@ class _BezierPageState extends State<BezierPage> {
},
onLoad: () async {
await Future.delayed(const Duration(seconds: 2));
if (!mounted) {
return;
}
setState(() {
_count += 5;
});
Expand Down
6 changes: 6 additions & 0 deletions example/lib/page/style/classical_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ class _ClassicPageState extends State<ClassicPage> {
? null
: () async {
await Future.delayed(const Duration(seconds: 2));
if (!mounted) {
return;
}
setState(() {
_count = 10;
});
Expand All @@ -102,6 +105,9 @@ class _ClassicPageState extends State<ClassicPage> {
? null
: () async {
await Future.delayed(const Duration(seconds: 2));
if (!mounted) {
return;
}
setState(() {
_count += 5;
});
Expand Down
6 changes: 6 additions & 0 deletions example/lib/page/style/delivery_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ class _DeliveryPageState extends State<DeliveryPage> {
),
onRefresh: () async {
await Future.delayed(const Duration(seconds: 4));
if (!mounted) {
return;
}
setState(() {
_count = 10;
});
Expand All @@ -52,6 +55,9 @@ class _DeliveryPageState extends State<DeliveryPage> {
},
onLoad: () async {
await Future.delayed(const Duration(seconds: 4));
if (!mounted) {
return;
}
setState(() {
_count += 5;
});
Expand Down
6 changes: 6 additions & 0 deletions example/lib/page/style/halloween_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ class _HalloweenPageState extends State<HalloweenPage> {
),
onRefresh: () async {
await Future.delayed(const Duration(seconds: 4));
if (!mounted) {
return;
}
setState(() {
_count = 10;
});
Expand All @@ -51,6 +54,9 @@ class _HalloweenPageState extends State<HalloweenPage> {
},
onLoad: () async {
await Future.delayed(const Duration(seconds: 4));
if (!mounted) {
return;
}
setState(() {
_count += 5;
});
Expand Down
6 changes: 6 additions & 0 deletions example/lib/page/style/material_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ class _MaterialIndicatorPageState extends State<MaterialIndicatorPage> {
),
onRefresh: () async {
await Future.delayed(const Duration(seconds: 2));
if (!mounted) {
return;
}
setState(() {
_count = 10;
});
Expand All @@ -74,6 +77,9 @@ class _MaterialIndicatorPageState extends State<MaterialIndicatorPage> {
},
onLoad: () async {
await Future.delayed(const Duration(seconds: 2));
if (!mounted) {
return;
}
setState(() {
_count += 5;
});
Expand Down
6 changes: 6 additions & 0 deletions example/lib/page/style/phoenix_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ class _PhoenixPageState extends State<PhoenixPage> {
),
onRefresh: () async {
await Future.delayed(const Duration(seconds: 2));
if (!mounted) {
return;
}
setState(() {
_count = 10;
});
Expand All @@ -55,6 +58,9 @@ class _PhoenixPageState extends State<PhoenixPage> {
},
onLoad: () async {
await Future.delayed(const Duration(seconds: 2));
if (!mounted) {
return;
}
setState(() {
_count += 5;
});
Expand Down
6 changes: 6 additions & 0 deletions example/lib/page/style/skating_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ class _SkatingPageState extends State<SkatingPage> {
),
onRefresh: () async {
await Future.delayed(const Duration(seconds: 4));
if (!mounted) {
return;
}
setState(() {
_count = 10;
});
Expand All @@ -51,6 +54,9 @@ class _SkatingPageState extends State<SkatingPage> {
},
onLoad: () async {
await Future.delayed(const Duration(seconds: 4));
if (!mounted) {
return;
}
setState(() {
_count += 5;
});
Expand Down
6 changes: 6 additions & 0 deletions example/lib/page/style/space_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ class _SpacePageState extends State<SpacePage> {
),
onRefresh: () async {
await Future.delayed(const Duration(seconds: 4));
if (!mounted) {
return;
}
setState(() {
_count = 10;
});
Expand All @@ -51,6 +54,9 @@ class _SpacePageState extends State<SpacePage> {
},
onLoad: () async {
await Future.delayed(const Duration(seconds: 4));
if (!mounted) {
return;
}
setState(() {
_count += 5;
});
Expand Down
6 changes: 6 additions & 0 deletions example/lib/page/style/squats_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ class _SquatsPageState extends State<SquatsPage> {
),
onRefresh: () async {
await Future.delayed(const Duration(seconds: 4));
if (!mounted) {
return;
}
setState(() {
_count = 10;
});
Expand All @@ -51,6 +54,9 @@ class _SquatsPageState extends State<SquatsPage> {
},
onLoad: () async {
await Future.delayed(const Duration(seconds: 4));
if (!mounted) {
return;
}
setState(() {
_count += 5;
});
Expand Down
6 changes: 6 additions & 0 deletions example/lib/page/style/taurus_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ class _TaurusPageState extends State<TaurusPage> {
),
onRefresh: () async {
await Future.delayed(const Duration(seconds: 4));
if (!mounted) {
return;
}
setState(() {
_count = 10;
});
Expand All @@ -55,6 +58,9 @@ class _TaurusPageState extends State<TaurusPage> {
},
onLoad: () async {
await Future.delayed(const Duration(seconds: 4));
if (!mounted) {
return;
}
setState(() {
_count += 5;
});
Expand Down

0 comments on commit 304cf80

Please sign in to comment.