@@ -34,7 +34,10 @@ class HomeScreen extends StatefulWidget {
3434}
3535
3636class _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