add sync data package, enable offline display of mzansi wallet, about mih & mzansi ai
This commit is contained in:
parent
f588e9f715
commit
6ad1ea613c
18 changed files with 826 additions and 833 deletions
42
mih_ui/lib/mih_hive/about_mih_hive_data.dart
Normal file
42
mih_ui/lib/mih_hive/about_mih_hive_data.dart
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
import 'package:hive_ce_flutter/adapters.dart';
|
||||
import 'package:ken_logger/ken_logger.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_services/mih_business_details_services.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_services/mih_user_services.dart';
|
||||
|
||||
class AboutMihHiveData {
|
||||
final Box<int> _mihUserBusinessCountBox = Hive.box<int>('about_mih_box');
|
||||
|
||||
static const String kUserCountKey = 'current_user_count';
|
||||
static const String kBusinessCountKey = 'current_user_count';
|
||||
|
||||
// Get Data from local storage
|
||||
int? getcachedUserCount() => _mihUserBusinessCountBox.get(kUserCountKey);
|
||||
int? getcachedBusinessCount() =>
|
||||
_mihUserBusinessCountBox.get(kBusinessCountKey);
|
||||
|
||||
// Caching Data to local storage
|
||||
Future<void> cacheUserCount(int remoteUserCount) async {
|
||||
await _mihUserBusinessCountBox.put(kUserCountKey, remoteUserCount);
|
||||
KenLogger.success("MIH User Count Cached");
|
||||
}
|
||||
|
||||
Future<void> cacheBusinessCount(int remoteBusinessCount) async {
|
||||
await _mihUserBusinessCountBox.put(kUserCountKey, remoteBusinessCount);
|
||||
KenLogger.success("MIH Business Count Cached");
|
||||
}
|
||||
|
||||
// Sync Local Data from data from MIH Server
|
||||
Future<bool> syncAboutMihDataWithServer() async {
|
||||
try {
|
||||
int remoteUserCount = await MihUserServices().fetchUserCount();
|
||||
cacheUserCount(remoteUserCount);
|
||||
int remoteBusinessCount =
|
||||
await MihBusinessDetailsServices().fetchBusinessCount();
|
||||
cacheBusinessCount(remoteBusinessCount);
|
||||
return true;
|
||||
} catch (error) {
|
||||
KenLogger.warning("MIH App Operating in Offline Mode. Sync Paused");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -159,7 +159,7 @@ class MzansiProfileHiveData {
|
|||
}
|
||||
return true;
|
||||
} catch (error) {
|
||||
KenLogger.warning("App Operating in Offline Mode. Sync Paused");
|
||||
KenLogger.warning("MIH App Operating in Offline Mode. Sync Paused");
|
||||
return false;
|
||||
// KenLogger.warning("App operating offline mode. Sync paused: $error");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ class MzansiWalletHiveData {
|
|||
cacheFavLoyaltyCardsData(remoteFavLoyaltyCards);
|
||||
return true;
|
||||
} catch (error) {
|
||||
KenLogger.warning("App Operating in Offline Mode. Sync Paused");
|
||||
KenLogger.warning("MIH App Operating in Offline Mode. Sync Paused");
|
||||
return false;
|
||||
// KenLogger.warning("App operating offline mode. Sync paused: $error");
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue