feat: improved refresh logic
This commit is contained in:
parent
41d4ed4a2a
commit
25ffb755c1
@ -70,19 +70,52 @@ class MainPage extends StatefulWidget {
|
|||||||
createState() => _MainPageState();
|
createState() => _MainPageState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _MainPageState extends State<MainPage> {
|
class _MainPageState extends State<MainPage> with WidgetsBindingObserver {
|
||||||
int _currentIndex = 0;
|
int _currentIndex = 0;
|
||||||
final List<Widget> _pages = [
|
final List<Widget> _pages = [
|
||||||
const MapPage(),
|
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) {
|
void _onItemTapped(int index) {
|
||||||
setState(() {
|
setState(() {
|
||||||
_currentIndex = index;
|
_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
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
|
Loading…
Reference in New Issue
Block a user