flutterstatefulwidgetstatelesswidget

use AppLifecycleState in StatelessWidget


in StatefulWidget when need to work with AppLifecycleState we work with WidgetsBindingObserver

  @override
initState() {
super.initState();
WidgetsBinding.instance.addObserver(this);
 }
@override
void dispose() {
WidgetsBinding.instance.removeObserver(this);
super.dispose();
}
@override
void didChangeAppLifecycleState(AppLifecycleState state){}

how to do this in StatelessWidget I search about this all show with StatefulWidget My Question it's must convert StatelessWidget to StatefulWidget?


Solution

  • You have to convert your widget to stateful and then control app life cycle in state class. There is no workaround.