feat: improved refresh logic
This commit is contained in:
		@ -70,19 +70,52 @@ class MainPage extends StatefulWidget {
 | 
			
		||||
  createState() => _MainPageState();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
class _MainPageState extends State<MainPage> {
 | 
			
		||||
class _MainPageState extends State<MainPage> with WidgetsBindingObserver {
 | 
			
		||||
  int _currentIndex = 0;
 | 
			
		||||
  final List<Widget> _pages = [
 | 
			
		||||
    const MapPage(),
 | 
			
		||||
    const SettingsPage(), // Assume this is your settings page widget
 | 
			
		||||
    const SettingsPage(),
 | 
			
		||||
  ];
 | 
			
		||||
 | 
			
		||||
  // Variable to keep track of the last lifecycle state
 | 
			
		||||
  AppLifecycleState? _lastLifecycleState;
 | 
			
		||||
 | 
			
		||||
  @override
 | 
			
		||||
  void initState() {
 | 
			
		||||
    super.initState();
 | 
			
		||||
    WidgetsBinding.instance.addObserver(this);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @override
 | 
			
		||||
  void dispose() {
 | 
			
		||||
    WidgetsBinding.instance.removeObserver(this);
 | 
			
		||||
    super.dispose();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  void _onItemTapped(int index) {
 | 
			
		||||
    setState(() {
 | 
			
		||||
      _currentIndex = index;
 | 
			
		||||
    });
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  // Listen for app lifecycle changes
 | 
			
		||||
  @override
 | 
			
		||||
  void didChangeAppLifecycleState(AppLifecycleState state) {
 | 
			
		||||
    // Check if the app is transitioning from paused to resumed
 | 
			
		||||
    print('DEBUG: lifecycle state changed from $_lastLifecycleState to $state');
 | 
			
		||||
    if (_lastLifecycleState == AppLifecycleState.paused &&
 | 
			
		||||
        (state == AppLifecycleState.resumed ||
 | 
			
		||||
            state == AppLifecycleState.inactive ||
 | 
			
		||||
            state == AppLifecycleState.detached ||
 | 
			
		||||
            state == AppLifecycleState.hidden)) {
 | 
			
		||||
      print('DEBUG: app is unpaused, triggering refresh');
 | 
			
		||||
      // Trigger the refresh when the app is "unpaused"
 | 
			
		||||
      context.read<RefreshCubit>().triggerRefresh();
 | 
			
		||||
    }
 | 
			
		||||
    // Update the last lifecycle state
 | 
			
		||||
    _lastLifecycleState = state;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @override
 | 
			
		||||
  Widget build(BuildContext context) {
 | 
			
		||||
    return Scaffold(
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user