Skip to content

Commit f401ac4

Browse files
fix: Display randomly disappears due to missing state update (#1313)
1 parent 86778fe commit f401ac4

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

lib/view/homescreen.dart

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ class HomeScreen extends StatefulWidget {
3434
}
3535

3636
class _HomeScreenState extends State<HomeScreen>
37-
with TickerProviderStateMixin, AutomaticKeepAliveClientMixin {
37+
with
38+
TickerProviderStateMixin,
39+
AutomaticKeepAliveClientMixin,
40+
WidgetsBindingObserver {
3841
late final TabController _tabController;
3942
AnimationBadgeProvider animationProvider = AnimationBadgeProvider();
4043
late SpeedDialProvider speedDialProvider;
@@ -52,6 +55,7 @@ class _HomeScreenState extends State<HomeScreen>
5255

5356
@override
5457
void initState() {
58+
WidgetsBinding.instance.addObserver(this);
5559
inlineimagecontroller.addListener(handleTextChange);
5660
_setPortraitOrientation();
5761
WidgetsBinding.instance.addPostFrameCallback((_) {
@@ -60,7 +64,6 @@ class _HomeScreenState extends State<HomeScreen>
6064
_startImageCaching();
6165
speedDialProvider = SpeedDialProvider(animationProvider);
6266
super.initState();
63-
6467
_tabController = TabController(length: 3, vsync: this);
6568
}
6669

@@ -102,6 +105,7 @@ class _HomeScreenState extends State<HomeScreen>
102105

103106
@override
104107
void dispose() {
108+
WidgetsBinding.instance.removeObserver(this);
105109
inlineimagecontroller.removeListener(handleTextChange);
106110
animationProvider.stopAnimation();
107111
inlineImageProvider.getController().removeListener(_controllerListner);
@@ -341,4 +345,19 @@ class _HomeScreenState extends State<HomeScreen>
341345

342346
@override
343347
bool get wantKeepAlive => true;
348+
349+
@override
350+
void didChangeAppLifecycleState(AppLifecycleState state) {
351+
super.didChangeAppLifecycleState(state);
352+
if (state == AppLifecycleState.resumed) {
353+
inlineimagecontroller.clear();
354+
previousText = '';
355+
animationProvider.stopAllAnimations();
356+
animationProvider.initializeAnimation();
357+
if (mounted) setState(() {});
358+
} else if (state == AppLifecycleState.paused ||
359+
state == AppLifecycleState.inactive) {
360+
animationProvider.stopAnimation();
361+
}
362+
}
344363
}

0 commit comments

Comments
 (0)