0

Is there any solution for listening to lifecycle events for a StatelessWidget when the app is in background / foreground ? There is no StatefulWidget on that particular screen. I am using Getx() controller to observe data changes.

Niaz Ahmed
  • 220
  • 2
  • 12

3 Answers3

1

Use this code for stateless widget

SystemChannels.lifecycle.setMessageHandler((msg) async {
  print('SystemChannels---> $msg');
});
abdulec90
  • 262
  • 3
  • 11
0

better use statefulwidgets for listen to lifecycle events

Janvi Patel
  • 242
  • 1
  • 12
0

For GetX architechture you dont have to use StatefulWidget but to listen lifecycle changes, it seems like you have to use StatefulWidget.

Just override this method in a StatefulWidget.

  @override
Future<void> didChangeAppLifecycleState(AppLifecycleState state) async 
{
if (state == AppLifecycleState.paused) {}
else if (state == AppLifecycleState.resumed) {}
}
Iosif Pop
  • 372
  • 2
  • 14
rishabh mistry
  • 527
  • 3
  • 8