feat: Implement update checker and dialog for available app updates with localization support

This commit is contained in:
Janez T
2025-10-26 17:47:37 +01:00
parent 0eae963efc
commit 0f9974c1e9
26 changed files with 727 additions and 12 deletions

View File

@@ -1,3 +1,4 @@
import 'dart:io' show Platform;
import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:provider/provider.dart';
@@ -13,6 +14,8 @@ import 'providers/app_provider.dart';
import 'services/tile_cache_service.dart';
import 'services/notification_service.dart';
import 'services/locale_preferences.dart';
import 'services/update_checker_service.dart';
import 'widgets/update_dialog.dart';
import 'screens/home_screen.dart';
import 'theme/app_theme.dart';
import 'l10n/app_localizations.dart';
@@ -49,6 +52,10 @@ class _MeshCoreSarAppState extends State<MeshCoreSarApp> {
// Check if we need to request location permissions
await _checkLocationPermissions();
// Check for app updates (Android only) - runs in background
// Shows dialog if update is available
_checkForUpdates();
setState(() {
_isInitialized = true;
});
@@ -95,6 +102,37 @@ class _MeshCoreSarAppState extends State<MeshCoreSarApp> {
});
}
/// Check for app updates on Android only
/// Shows dialog if update is available
Future<void> _checkForUpdates() async {
// Only check for updates on Android
if (!Platform.isAndroid) {
debugPrint('[UpdateChecker] Skipping update check (not Android)');
return;
}
try {
debugPrint('[UpdateChecker] Starting update check...');
final updateInfo = await UpdateCheckerService().checkForUpdate();
if (!updateInfo.isAvailable) {
debugPrint('[UpdateChecker] No update available');
return;
}
debugPrint('[UpdateChecker] Update available! Showing dialog...');
// Wait for widget tree to be built before showing dialog
WidgetsBinding.instance.addPostFrameCallback((_) {
if (mounted) {
UpdateDialog.show(context, updateInfo);
}
});
} catch (e) {
debugPrint('[UpdateChecker] Error checking for updates: $e');
}
}
@override
Widget build(BuildContext context) {
if (!_isInitialized) {