Sync data message when in Offline Mode

This commit is contained in:
yaso 2026-06-25 12:24:30 +02:00
parent 8d78fb6357
commit d722251d50
3 changed files with 15 additions and 8 deletions

View file

@ -1,5 +1,3 @@
import 'dart:math';
import 'package:hive_ce_flutter/hive_ce_flutter.dart'; import 'package:hive_ce_flutter/hive_ce_flutter.dart';
import 'package:ken_logger/ken_logger.dart'; import 'package:ken_logger/ken_logger.dart';
import 'package:mzansi_innovation_hub/mih_objects/app_user.dart'; import 'package:mzansi_innovation_hub/mih_objects/app_user.dart';
@ -130,7 +128,7 @@ class MzansiProfileHiveData {
} }
// Sync Local Data from data from MIH Server // Sync Local Data from data from MIH Server
Future<void> syncProfileDataWithServer() async { Future<bool> syncProfileDataWithServer() async {
try { try {
AppUser? remoteUser = await MihUserServices().getMyUserDetailsV2(); AppUser? remoteUser = await MihUserServices().getMyUserDetailsV2();
if (remoteUser != null) { if (remoteUser != null) {
@ -159,8 +157,10 @@ class MzansiProfileHiveData {
remoteBusiness.business_id); remoteBusiness.business_id);
cacheBusinessProfileLinksData(remoteBusinessLinks); cacheBusinessProfileLinksData(remoteBusinessLinks);
} }
return true;
} catch (error) { } catch (error) {
KenLogger.warning("App operating offline mode. Sync paused"); KenLogger.warning("App Operating in Offline Mode. Sync Paused");
return false;
// KenLogger.warning("App operating offline mode. Sync paused: $error"); // KenLogger.warning("App operating offline mode. Sync paused: $error");
} }
} }

View file

@ -88,11 +88,17 @@ class _MihHomeState extends State<MihHome> {
RefreshIndicator( RefreshIndicator(
key: mzansiProfileProvider.refreshIndicatorKey, key: mzansiProfileProvider.refreshIndicatorKey,
onRefresh: () async { onRefresh: () async {
await mzansiProfileProvider.syncWithMihServerData(); bool success =
await mzansiProfileProvider.syncWithMihServerData();
if (context.mounted) { if (context.mounted) {
ScaffoldMessenger.of(context).showSnackBar( ScaffoldMessenger.of(context).showSnackBar(
MihSnackBar( MihSnackBar(
child: Text("Data Synced with MIH Server."), child: Text(
success
? "Data Synced with MIH Server."
: "MIH App operation in Offline Mode",
),
// backgroundColor: success ? null : MihColors.red(),
), ),
); );
} }

View file

@ -72,9 +72,10 @@ class MzansiProfileProvider extends ChangeNotifier {
notifyListeners(); notifyListeners();
} }
Future<void> syncWithMihServerData() async { Future<bool> syncWithMihServerData() async {
await _hiveData.syncProfileDataWithServer(); bool success = await _hiveData.syncProfileDataWithServer();
loadCachedProfileState(); loadCachedProfileState();
return success;
} }
void triggerRefresh() { void triggerRefresh() {