fix(mobile): move update check to HomeShellPage with valid context

- Move checkForAppUpdate from SplashPage to HomeShellPage
- Use WidgetsBindingObserver to check on app resume
- Add 24-hour interval check to avoid frequent API calls
- Fix: context.go() invalidates context, so check was never executed

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
hailin 2025-12-10 03:05:19 -08:00
parent 12116ff164
commit 908f50ab11
2 changed files with 53 additions and 5 deletions

View File

@ -69,8 +69,8 @@ class _SplashPageState extends ConsumerState<SplashPage> {
context.go(RoutePaths.onboarding);
}
//
checkForAppUpdate(context);
// HomeShellPage
// checkForAppUpdate context.go() context
}
@override

View File

@ -4,13 +4,61 @@ import 'package:go_router/go_router.dart';
import '../../../../core/theme/app_colors.dart';
import '../../../../core/theme/app_dimensions.dart';
import '../../../../routes/route_paths.dart';
import '../../../../bootstrap.dart';
import '../widgets/bottom_nav_bar.dart';
class HomeShellPage extends ConsumerWidget {
class HomeShellPage extends ConsumerStatefulWidget {
final Widget child;
const HomeShellPage({super.key, required this.child});
@override
ConsumerState<HomeShellPage> createState() => _HomeShellPageState();
}
class _HomeShellPageState extends ConsumerState<HomeShellPage>
with WidgetsBindingObserver {
///
static DateTime? _lastCheckTime;
/// 24
static const _checkInterval = Duration(hours: 24);
@override
void initState() {
super.initState();
WidgetsBinding.instance.addObserver(this);
//
WidgetsBinding.instance.addPostFrameCallback((_) {
_checkForUpdateIfNeeded();
});
}
@override
void dispose() {
WidgetsBinding.instance.removeObserver(this);
super.dispose();
}
@override
void didChangeAppLifecycleState(AppLifecycleState state) {
//
if (state == AppLifecycleState.resumed) {
_checkForUpdateIfNeeded();
}
}
Future<void> _checkForUpdateIfNeeded() async {
final now = DateTime.now();
// 24
if (_lastCheckTime == null ||
now.difference(_lastCheckTime!) > _checkInterval) {
_lastCheckTime = now;
await checkForAppUpdate(context);
}
}
int _getCurrentIndex(BuildContext context) {
final location = GoRouterState.of(context).uri.path;
if (location.startsWith(RoutePaths.ranking)) return 0;
@ -38,9 +86,9 @@ class HomeShellPage extends ConsumerWidget {
}
@override
Widget build(BuildContext context, WidgetRef ref) {
Widget build(BuildContext context) {
return Scaffold(
body: child,
body: widget.child,
bottomNavigationBar: BottomNavBar(
currentIndex: _getCurrentIndex(context),
onTap: (index) => _onTabTapped(context, index),