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:ken_logger/ken_logger.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
Future<void> syncProfileDataWithServer() async {
Future<bool> syncProfileDataWithServer() async {
try {
AppUser? remoteUser = await MihUserServices().getMyUserDetailsV2();
if (remoteUser != null) {
@ -159,8 +157,10 @@ class MzansiProfileHiveData {
remoteBusiness.business_id);
cacheBusinessProfileLinksData(remoteBusinessLinks);
}
return true;
} 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");
}
}

View file

@ -88,11 +88,17 @@ class _MihHomeState extends State<MihHome> {
RefreshIndicator(
key: mzansiProfileProvider.refreshIndicatorKey,
onRefresh: () async {
bool success =
await mzansiProfileProvider.syncWithMihServerData();
if (context.mounted) {
ScaffoldMessenger.of(context).showSnackBar(
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();
}
Future<void> syncWithMihServerData() async {
await _hiveData.syncProfileDataWithServer();
Future<bool> syncWithMihServerData() async {
bool success = await _hiveData.syncProfileDataWithServer();
loadCachedProfileState();
return success;
}
void triggerRefresh() {