complete mzansi personal and business profile get & store data offline mode
This commit is contained in:
parent
d42337fc6c
commit
8d78fb6357
13 changed files with 240 additions and 61 deletions
|
|
@ -12,6 +12,7 @@ import 'package:mzansi_innovation_hub/mih_config/mih_go_router.dart';
|
||||||
import 'package:mzansi_innovation_hub/mih_hive/hive_registrar.g.dart';
|
import 'package:mzansi_innovation_hub/mih_hive/hive_registrar.g.dart';
|
||||||
import 'package:mzansi_innovation_hub/mih_objects/app_user.dart';
|
import 'package:mzansi_innovation_hub/mih_objects/app_user.dart';
|
||||||
import 'package:mzansi_innovation_hub/mih_objects/business.dart';
|
import 'package:mzansi_innovation_hub/mih_objects/business.dart';
|
||||||
|
import 'package:mzansi_innovation_hub/mih_objects/business_employee.dart';
|
||||||
import 'package:mzansi_innovation_hub/mih_objects/business_user.dart';
|
import 'package:mzansi_innovation_hub/mih_objects/business_user.dart';
|
||||||
import 'package:mzansi_innovation_hub/mih_objects/profile_link.dart';
|
import 'package:mzansi_innovation_hub/mih_objects/profile_link.dart';
|
||||||
import 'package:mzansi_innovation_hub/mih_objects/user_consent.dart';
|
import 'package:mzansi_innovation_hub/mih_objects/user_consent.dart';
|
||||||
|
|
@ -36,6 +37,8 @@ void main() async {
|
||||||
await Hive.openBox<UserConsent>('user_consent_box');
|
await Hive.openBox<UserConsent>('user_consent_box');
|
||||||
await Hive.openBox<String>('image_urls_box');
|
await Hive.openBox<String>('image_urls_box');
|
||||||
await Hive.openBox<ProfileLink>('personal_profile_links_box');
|
await Hive.openBox<ProfileLink>('personal_profile_links_box');
|
||||||
|
await Hive.openBox<ProfileLink>('business_profile_links_box');
|
||||||
|
await Hive.openBox<BusinessEmployee>('business_employees_box');
|
||||||
|
|
||||||
// await Firebase.initializeApp(
|
// await Firebase.initializeApp(
|
||||||
// // options: DefaultFirebaseOptions.currentPlatform,
|
// // options: DefaultFirebaseOptions.currentPlatform,
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
import 'package:hive_ce/hive_ce.dart';
|
import 'package:hive_ce/hive_ce.dart';
|
||||||
import 'package:mzansi_innovation_hub/mih_objects/app_user.dart';
|
import 'package:mzansi_innovation_hub/mih_objects/app_user.dart';
|
||||||
import 'package:mzansi_innovation_hub/mih_objects/business.dart';
|
import 'package:mzansi_innovation_hub/mih_objects/business.dart';
|
||||||
|
import 'package:mzansi_innovation_hub/mih_objects/business_employee.dart';
|
||||||
import 'package:mzansi_innovation_hub/mih_objects/business_user.dart';
|
import 'package:mzansi_innovation_hub/mih_objects/business_user.dart';
|
||||||
import 'package:mzansi_innovation_hub/mih_objects/profile_link.dart';
|
import 'package:mzansi_innovation_hub/mih_objects/profile_link.dart';
|
||||||
import 'package:mzansi_innovation_hub/mih_objects/user_consent.dart';
|
import 'package:mzansi_innovation_hub/mih_objects/user_consent.dart';
|
||||||
|
|
@ -12,5 +13,6 @@ import 'package:mzansi_innovation_hub/mih_objects/user_consent.dart';
|
||||||
AdapterSpec<BusinessUser>(),
|
AdapterSpec<BusinessUser>(),
|
||||||
AdapterSpec<UserConsent>(),
|
AdapterSpec<UserConsent>(),
|
||||||
AdapterSpec<ProfileLink>(),
|
AdapterSpec<ProfileLink>(),
|
||||||
|
AdapterSpec<BusinessEmployee>(),
|
||||||
])
|
])
|
||||||
part 'hive_adapters.g.dart';
|
part 'hive_adapters.g.dart';
|
||||||
|
|
|
||||||
|
|
@ -283,3 +283,58 @@ class ProfileLinkAdapter extends TypeAdapter<ProfileLink> {
|
||||||
runtimeType == other.runtimeType &&
|
runtimeType == other.runtimeType &&
|
||||||
typeId == other.typeId;
|
typeId == other.typeId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class BusinessEmployeeAdapter extends TypeAdapter<BusinessEmployee> {
|
||||||
|
@override
|
||||||
|
final typeId = 5;
|
||||||
|
|
||||||
|
@override
|
||||||
|
BusinessEmployee read(BinaryReader reader) {
|
||||||
|
final numOfFields = reader.readByte();
|
||||||
|
final fields = <int, dynamic>{
|
||||||
|
for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(),
|
||||||
|
};
|
||||||
|
return BusinessEmployee(
|
||||||
|
fields[0] as String,
|
||||||
|
fields[1] as String,
|
||||||
|
fields[2] as String,
|
||||||
|
fields[3] as String,
|
||||||
|
fields[4] as String,
|
||||||
|
fields[5] as String,
|
||||||
|
fields[6] as String,
|
||||||
|
fields[7] as String,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void write(BinaryWriter writer, BusinessEmployee obj) {
|
||||||
|
writer
|
||||||
|
..writeByte(8)
|
||||||
|
..writeByte(0)
|
||||||
|
..write(obj.business_id)
|
||||||
|
..writeByte(1)
|
||||||
|
..write(obj.app_id)
|
||||||
|
..writeByte(2)
|
||||||
|
..write(obj.title)
|
||||||
|
..writeByte(3)
|
||||||
|
..write(obj.access)
|
||||||
|
..writeByte(4)
|
||||||
|
..write(obj.fname)
|
||||||
|
..writeByte(5)
|
||||||
|
..write(obj.lname)
|
||||||
|
..writeByte(6)
|
||||||
|
..write(obj.email)
|
||||||
|
..writeByte(7)
|
||||||
|
..write(obj.username);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
int get hashCode => typeId.hashCode;
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool operator ==(Object other) =>
|
||||||
|
identical(this, other) ||
|
||||||
|
other is BusinessEmployeeAdapter &&
|
||||||
|
runtimeType == other.runtimeType &&
|
||||||
|
typeId == other.typeId;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
# Generated by Hive CE
|
# Generated by Hive CE
|
||||||
# Manual modifications may be necessary for certain migrations
|
# Manual modifications may be necessary for certain migrations
|
||||||
# Check in to version control
|
# Check in to version control
|
||||||
nextTypeId: 5
|
nextTypeId: 6
|
||||||
types:
|
types:
|
||||||
AppUser:
|
AppUser:
|
||||||
typeId: 0
|
typeId: 0
|
||||||
|
|
@ -105,3 +105,23 @@ types:
|
||||||
index: 5
|
index: 5
|
||||||
order:
|
order:
|
||||||
index: 6
|
index: 6
|
||||||
|
BusinessEmployee:
|
||||||
|
typeId: 5
|
||||||
|
nextIndex: 8
|
||||||
|
fields:
|
||||||
|
business_id:
|
||||||
|
index: 0
|
||||||
|
app_id:
|
||||||
|
index: 1
|
||||||
|
title:
|
||||||
|
index: 2
|
||||||
|
access:
|
||||||
|
index: 3
|
||||||
|
fname:
|
||||||
|
index: 4
|
||||||
|
lname:
|
||||||
|
index: 5
|
||||||
|
email:
|
||||||
|
index: 6
|
||||||
|
username:
|
||||||
|
index: 7
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ extension HiveRegistrar on HiveInterface {
|
||||||
void registerAdapters() {
|
void registerAdapters() {
|
||||||
registerAdapter(AppUserAdapter());
|
registerAdapter(AppUserAdapter());
|
||||||
registerAdapter(BusinessAdapter());
|
registerAdapter(BusinessAdapter());
|
||||||
|
registerAdapter(BusinessEmployeeAdapter());
|
||||||
registerAdapter(BusinessUserAdapter());
|
registerAdapter(BusinessUserAdapter());
|
||||||
registerAdapter(ProfileLinkAdapter());
|
registerAdapter(ProfileLinkAdapter());
|
||||||
registerAdapter(UserConsentAdapter());
|
registerAdapter(UserConsentAdapter());
|
||||||
|
|
@ -19,6 +20,7 @@ extension IsolatedHiveRegistrar on IsolatedHiveInterface {
|
||||||
void registerAdapters() {
|
void registerAdapters() {
|
||||||
registerAdapter(AppUserAdapter());
|
registerAdapter(AppUserAdapter());
|
||||||
registerAdapter(BusinessAdapter());
|
registerAdapter(BusinessAdapter());
|
||||||
|
registerAdapter(BusinessEmployeeAdapter());
|
||||||
registerAdapter(BusinessUserAdapter());
|
registerAdapter(BusinessUserAdapter());
|
||||||
registerAdapter(ProfileLinkAdapter());
|
registerAdapter(ProfileLinkAdapter());
|
||||||
registerAdapter(UserConsentAdapter());
|
registerAdapter(UserConsentAdapter());
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,15 @@
|
||||||
|
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';
|
||||||
import 'package:mzansi_innovation_hub/mih_objects/business.dart';
|
import 'package:mzansi_innovation_hub/mih_objects/business.dart';
|
||||||
|
import 'package:mzansi_innovation_hub/mih_objects/business_employee.dart';
|
||||||
import 'package:mzansi_innovation_hub/mih_objects/business_user.dart';
|
import 'package:mzansi_innovation_hub/mih_objects/business_user.dart';
|
||||||
import 'package:mzansi_innovation_hub/mih_objects/profile_link.dart';
|
import 'package:mzansi_innovation_hub/mih_objects/profile_link.dart';
|
||||||
import 'package:mzansi_innovation_hub/mih_objects/user_consent.dart';
|
import 'package:mzansi_innovation_hub/mih_objects/user_consent.dart';
|
||||||
import 'package:mzansi_innovation_hub/mih_services/mih_business_details_services.dart';
|
import 'package:mzansi_innovation_hub/mih_services/mih_business_details_services.dart';
|
||||||
|
import 'package:mzansi_innovation_hub/mih_services/mih_business_employee_services.dart';
|
||||||
import 'package:mzansi_innovation_hub/mih_services/mih_file_services.dart';
|
import 'package:mzansi_innovation_hub/mih_services/mih_file_services.dart';
|
||||||
import 'package:mzansi_innovation_hub/mih_services/mih_my_business_user_services.dart';
|
import 'package:mzansi_innovation_hub/mih_services/mih_my_business_user_services.dart';
|
||||||
import 'package:mzansi_innovation_hub/mih_services/mih_profile_links_service.dart';
|
import 'package:mzansi_innovation_hub/mih_services/mih_profile_links_service.dart';
|
||||||
|
|
@ -21,7 +25,10 @@ class MzansiProfileHiveData {
|
||||||
Hive.box<UserConsent>('user_consent_box');
|
Hive.box<UserConsent>('user_consent_box');
|
||||||
final Box<ProfileLink> _personalProfileLinksBox =
|
final Box<ProfileLink> _personalProfileLinksBox =
|
||||||
Hive.box<ProfileLink>('personal_profile_links_box');
|
Hive.box<ProfileLink>('personal_profile_links_box');
|
||||||
|
final Box<ProfileLink> _businessProfileLinksBox =
|
||||||
|
Hive.box<ProfileLink>('business_profile_links_box');
|
||||||
|
final Box<BusinessEmployee> _businessEmployeesBox =
|
||||||
|
Hive.box<BusinessEmployee>('business_Employees_box');
|
||||||
final Box<String> _resolvedUrlsBox = Hive.box<String>('image_urls_box');
|
final Box<String> _resolvedUrlsBox = Hive.box<String>('image_urls_box');
|
||||||
|
|
||||||
static const String kUserKey = 'current_user';
|
static const String kUserKey = 'current_user';
|
||||||
|
|
@ -32,6 +39,7 @@ class MzansiProfileHiveData {
|
||||||
static const String kBusinessPicUrlKey = 'business_pic_url';
|
static const String kBusinessPicUrlKey = 'business_pic_url';
|
||||||
static const String kSignatureUrlKey = 'signature_url';
|
static const String kSignatureUrlKey = 'signature_url';
|
||||||
|
|
||||||
|
// Get Data from local storage
|
||||||
AppUser? getCachedUser() => _userBox.get(kUserKey);
|
AppUser? getCachedUser() => _userBox.get(kUserKey);
|
||||||
Business? getCachedBusiness() => _businessBox.get(kBusinessKey);
|
Business? getCachedBusiness() => _businessBox.get(kBusinessKey);
|
||||||
BusinessUser? getCachedBusinessUser() =>
|
BusinessUser? getCachedBusinessUser() =>
|
||||||
|
|
@ -40,12 +48,26 @@ class MzansiProfileHiveData {
|
||||||
String? getCachedUserPicUrl() => _resolvedUrlsBox.get(kUserPicUrlKey);
|
String? getCachedUserPicUrl() => _resolvedUrlsBox.get(kUserPicUrlKey);
|
||||||
String? getCachedBusinessPicUrl() => _resolvedUrlsBox.get(kBusinessPicUrlKey);
|
String? getCachedBusinessPicUrl() => _resolvedUrlsBox.get(kBusinessPicUrlKey);
|
||||||
String? getCachedSignatureUrl() => _resolvedUrlsBox.get(kSignatureUrlKey);
|
String? getCachedSignatureUrl() => _resolvedUrlsBox.get(kSignatureUrlKey);
|
||||||
|
|
||||||
List<ProfileLink> getCachedPersonalProfileLinks() {
|
List<ProfileLink> getCachedPersonalProfileLinks() {
|
||||||
final links = _personalProfileLinksBox.values.toList();
|
final links = _personalProfileLinksBox.values.toList();
|
||||||
links.sort((a, b) => a.order.compareTo(b.order));
|
links.sort((a, b) => a.order.compareTo(b.order));
|
||||||
return links;
|
return links;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
List<ProfileLink> getCachedBusinessProfileLinks() {
|
||||||
|
final links = _businessProfileLinksBox.values.toList();
|
||||||
|
links.sort((a, b) => a.order.compareTo(b.order));
|
||||||
|
return links;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<BusinessEmployee> getCachedBusinessEmployees() {
|
||||||
|
final employees = _businessEmployeesBox.values.toList();
|
||||||
|
employees.sort((a, b) => a.fname.compareTo(b.fname));
|
||||||
|
return employees;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Caching Data to local storage
|
||||||
Future<void> cacheUserData(AppUser remoteUser) async {
|
Future<void> cacheUserData(AppUser remoteUser) async {
|
||||||
await _userBox.put(kUserKey, remoteUser);
|
await _userBox.put(kUserKey, remoteUser);
|
||||||
if (remoteUser.pro_pic_path.isNotEmpty) {
|
if (remoteUser.pro_pic_path.isNotEmpty) {
|
||||||
|
|
@ -53,10 +75,12 @@ class MzansiProfileHiveData {
|
||||||
await MihFileApi.getMinioFileUrl(remoteUser.pro_pic_path);
|
await MihFileApi.getMinioFileUrl(remoteUser.pro_pic_path);
|
||||||
await _resolvedUrlsBox.put(kUserPicUrlKey, userPicUrl);
|
await _resolvedUrlsBox.put(kUserPicUrlKey, userPicUrl);
|
||||||
}
|
}
|
||||||
|
KenLogger.success("User Profile Cached");
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> cacheUserConsentData(UserConsent remoteConsent) async {
|
Future<void> cacheUserConsentData(UserConsent remoteConsent) async {
|
||||||
await _userConsentBox.put(kConsentKey, remoteConsent);
|
await _userConsentBox.put(kConsentKey, remoteConsent);
|
||||||
|
KenLogger.success("User Consent Cached");
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> cacheBusinessData(Business remoteBusiness) async {
|
Future<void> cacheBusinessData(Business remoteBusiness) async {
|
||||||
|
|
@ -71,6 +95,7 @@ class MzansiProfileHiveData {
|
||||||
if (remoteBizUser != null) {
|
if (remoteBizUser != null) {
|
||||||
cacheBusinessUserData(remoteBizUser);
|
cacheBusinessUserData(remoteBizUser);
|
||||||
}
|
}
|
||||||
|
KenLogger.success("Busines Profile Cached");
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> cacheBusinessUserData(BusinessUser remoteBizUser) async {
|
Future<void> cacheBusinessUserData(BusinessUser remoteBizUser) async {
|
||||||
|
|
@ -80,33 +105,59 @@ class MzansiProfileHiveData {
|
||||||
await MihFileApi.getMinioFileUrl(remoteBizUser.sig_path);
|
await MihFileApi.getMinioFileUrl(remoteBizUser.sig_path);
|
||||||
await _resolvedUrlsBox.put(kSignatureUrlKey, signatureUrl);
|
await _resolvedUrlsBox.put(kSignatureUrlKey, signatureUrl);
|
||||||
}
|
}
|
||||||
|
KenLogger.success("Busines User Profile Cached");
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> cacheBusinessEmployeesData(
|
||||||
|
List<BusinessEmployee> remoteBusinessEmployeeList) async {
|
||||||
|
await _businessEmployeesBox.clear();
|
||||||
|
await _businessEmployeesBox.addAll(remoteBusinessEmployeeList);
|
||||||
|
KenLogger.success("Business Employees Cached");
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> cachePersonalProfileLinksData(
|
Future<void> cachePersonalProfileLinksData(
|
||||||
List<ProfileLink> remoteLinks) async {
|
List<ProfileLink> remotePersonalLinks) async {
|
||||||
await _personalProfileLinksBox.clear();
|
await _personalProfileLinksBox.clear();
|
||||||
await _personalProfileLinksBox.addAll(remoteLinks);
|
await _personalProfileLinksBox.addAll(remotePersonalLinks);
|
||||||
|
KenLogger.success("Personal Profile Links Cached");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> cacheBusinessProfileLinksData(
|
||||||
|
List<ProfileLink> remoteBusinessLinks) async {
|
||||||
|
await _businessProfileLinksBox.clear();
|
||||||
|
await _businessProfileLinksBox.addAll(remoteBusinessLinks);
|
||||||
|
KenLogger.success("Personal Profile Links Cached");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sync Local Data from data from MIH Server
|
||||||
Future<void> syncProfileDataWithServer() async {
|
Future<void> syncProfileDataWithServer() async {
|
||||||
try {
|
try {
|
||||||
AppUser? remoteUser = await MihUserServices().getMyUserDetailsV2();
|
AppUser? remoteUser = await MihUserServices().getMyUserDetailsV2();
|
||||||
if (remoteUser != null) {
|
if (remoteUser != null) {
|
||||||
cacheUserData(remoteUser);
|
cacheUserData(remoteUser);
|
||||||
|
|
||||||
UserConsent? remoteConsent =
|
UserConsent? remoteConsent =
|
||||||
await MihUserConsentServices().getUserConsentStatusV2();
|
await MihUserConsentServices().getUserConsentStatusV2();
|
||||||
if (remoteConsent != null) {
|
if (remoteConsent != null) {
|
||||||
cacheUserConsentData(remoteConsent);
|
cacheUserConsentData(remoteConsent);
|
||||||
}
|
}
|
||||||
final remoteLinks = await MihProfileLinksServices.getUserProfileLinksV2(
|
final remotePersonalLinks =
|
||||||
|
await MihProfileLinksServices.getUserProfileLinksV2(
|
||||||
remoteUser.app_id);
|
remoteUser.app_id);
|
||||||
await cachePersonalProfileLinksData(remoteLinks);
|
cachePersonalProfileLinksData(remotePersonalLinks);
|
||||||
}
|
}
|
||||||
Business? remoteBusiness =
|
Business? remoteBusiness =
|
||||||
await MihBusinessDetailsServices().getBusinessDetailsByUserV2();
|
await MihBusinessDetailsServices().getBusinessDetailsByUserV2();
|
||||||
if (remoteBusiness != null) {
|
if (remoteBusiness != null) {
|
||||||
cacheBusinessData(remoteBusiness);
|
cacheBusinessData(remoteBusiness);
|
||||||
|
|
||||||
|
final remoteBusinessEmployeeList = await MihBusinessEmployeeServices()
|
||||||
|
.fetchEmployeesV2(remoteBusiness.business_id);
|
||||||
|
cacheBusinessEmployeesData(remoteBusinessEmployeeList);
|
||||||
|
|
||||||
|
final remoteBusinessLinks =
|
||||||
|
await MihProfileLinksServices.getBusinessProfileLinksV2(
|
||||||
|
remoteBusiness.business_id);
|
||||||
|
cacheBusinessProfileLinksData(remoteBusinessLinks);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
KenLogger.warning("App operating offline mode. Sync paused");
|
KenLogger.warning("App operating offline mode. Sync paused");
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ import 'package:go_router/go_router.dart';
|
||||||
import 'package:mih_package_toolkit/mih_package_toolkit.dart';
|
import 'package:mih_package_toolkit/mih_package_toolkit.dart';
|
||||||
import 'package:mzansi_innovation_hub/main.dart';
|
import 'package:mzansi_innovation_hub/main.dart';
|
||||||
import 'package:mzansi_innovation_hub/mih_objects/arguments.dart';
|
import 'package:mzansi_innovation_hub/mih_objects/arguments.dart';
|
||||||
|
import 'package:mzansi_innovation_hub/mih_packages/mih_home/package_tile/mih_home_refresh_tile.dart';
|
||||||
import 'package:mzansi_innovation_hub/mih_providers/mzansi_ai_provider.dart';
|
import 'package:mzansi_innovation_hub/mih_providers/mzansi_ai_provider.dart';
|
||||||
import 'package:mzansi_innovation_hub/mih_providers/mzansi_profile_provider.dart';
|
import 'package:mzansi_innovation_hub/mih_providers/mzansi_profile_provider.dart';
|
||||||
import 'package:mzansi_innovation_hub/mih_packages/about_mih/package_tile/about_mih_tile.dart';
|
import 'package:mzansi_innovation_hub/mih_packages/about_mih/package_tile/about_mih_tile.dart';
|
||||||
|
|
@ -129,6 +130,12 @@ class _MihBusinessHomeState extends State<MihBusinessHome>
|
||||||
packageSize: packageSize,
|
packageSize: packageSize,
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
|
//=============== About MIH ===============
|
||||||
|
temp.add({
|
||||||
|
"Sync Data": MihHomeRefreshTile(
|
||||||
|
packageSize: packageSize,
|
||||||
|
)
|
||||||
|
});
|
||||||
return temp;
|
return temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ import 'package:mih_package_toolkit/mih_package_toolkit.dart';
|
||||||
import 'package:mzansi_innovation_hub/main.dart';
|
import 'package:mzansi_innovation_hub/main.dart';
|
||||||
import 'package:mzansi_innovation_hub/mih_config/mih_env.dart';
|
import 'package:mzansi_innovation_hub/mih_config/mih_env.dart';
|
||||||
import 'package:mzansi_innovation_hub/mih_package_components/Example/package_tiles/test_package_tile.dart';
|
import 'package:mzansi_innovation_hub/mih_package_components/Example/package_tiles/test_package_tile.dart';
|
||||||
|
import 'package:mzansi_innovation_hub/mih_packages/mih_home/package_tile/mih_home_refresh_tile.dart';
|
||||||
import 'package:mzansi_innovation_hub/mih_packages/mzansi_profile/business_profile/package_tiles/mzansi_setup_business_profile_tile.dart';
|
import 'package:mzansi_innovation_hub/mih_packages/mzansi_profile/business_profile/package_tiles/mzansi_setup_business_profile_tile.dart';
|
||||||
import 'package:mzansi_innovation_hub/mih_providers/mzansi_ai_provider.dart';
|
import 'package:mzansi_innovation_hub/mih_providers/mzansi_ai_provider.dart';
|
||||||
import 'package:mzansi_innovation_hub/mih_packages/about_mih/package_tile/about_mih_tile.dart';
|
import 'package:mzansi_innovation_hub/mih_packages/about_mih/package_tile/about_mih_tile.dart';
|
||||||
|
|
@ -138,6 +139,12 @@ class _MihPersonalHomeState extends State<MihPersonalHome>
|
||||||
packageSize: packageSize,
|
packageSize: packageSize,
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
|
//=============== About MIH ===============
|
||||||
|
temp.add({
|
||||||
|
"Sync Data": MihHomeRefreshTile(
|
||||||
|
packageSize: packageSize,
|
||||||
|
)
|
||||||
|
});
|
||||||
//=============== Dev ===============
|
//=============== Dev ===============
|
||||||
if (AppEnviroment.getEnv() == "Dev") {
|
if (AppEnviroment.getEnv() == "Dev") {
|
||||||
temp.add({
|
temp.add({
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ class BusinesProfile extends StatefulWidget {
|
||||||
}
|
}
|
||||||
|
|
||||||
class _BusinesProfileState extends State<BusinesProfile> {
|
class _BusinesProfileState extends State<BusinesProfile> {
|
||||||
bool _isLoadingInitialData = true;
|
// bool _isLoadingInitialData = true;
|
||||||
late final MihBusinessDetails _businessDetails;
|
late final MihBusinessDetails _businessDetails;
|
||||||
late final MihMyBusinessUser _businessUser;
|
late final MihMyBusinessUser _businessUser;
|
||||||
late final MihMyBusinessTeam _businessTeam;
|
late final MihMyBusinessTeam _businessTeam;
|
||||||
|
|
@ -31,26 +31,18 @@ class _BusinesProfileState extends State<BusinesProfile> {
|
||||||
late final MihBusinessQrCode _businessQrCode;
|
late final MihBusinessQrCode _businessQrCode;
|
||||||
late final MihBusinessLinks _businessLinks;
|
late final MihBusinessLinks _businessLinks;
|
||||||
|
|
||||||
Future<void> _loadInitialData() async {
|
// Future<void> _loadInitialData() async {
|
||||||
setState(() {
|
// MzansiProfileProvider mzansiProfileProvider =
|
||||||
_isLoadingInitialData = true;
|
// context.read<MzansiProfileProvider>();
|
||||||
});
|
// mzansiProfileProvider.loadCachedProfileState();
|
||||||
MzansiProfileProvider mzansiProfileProvider =
|
// if (mzansiProfileProvider.user == null) {
|
||||||
context.read<MzansiProfileProvider>();
|
// mzansiProfileProvider.syncWithMihServerData();
|
||||||
if (mzansiProfileProvider.user == null) {
|
// }
|
||||||
await MihDataHelperServices().loadUserDataWithBusinessesData(
|
// setState(() {
|
||||||
mzansiProfileProvider,
|
// _isLoadingInitialData = false;
|
||||||
);
|
// });
|
||||||
}
|
// }
|
||||||
await MihProfileLinksServices.getBusinessProfileLinks(
|
//
|
||||||
mzansiProfileProvider, mzansiProfileProvider.business!.business_id);
|
|
||||||
await MihBusinessEmployeeServices()
|
|
||||||
.fetchEmployees(mzansiProfileProvider, context);
|
|
||||||
setState(() {
|
|
||||||
_isLoadingInitialData = false;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
|
|
@ -61,7 +53,7 @@ class _BusinesProfileState extends State<BusinesProfile> {
|
||||||
_businessReviews = MihBusinessReviews(business: null);
|
_businessReviews = MihBusinessReviews(business: null);
|
||||||
_businessLinks = MihBusinessLinks(viewMode: false);
|
_businessLinks = MihBusinessLinks(viewMode: false);
|
||||||
_businessQrCode = MihBusinessQrCode(business: null);
|
_businessQrCode = MihBusinessQrCode(business: null);
|
||||||
_loadInitialData();
|
// _loadInitialData();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|
@ -69,13 +61,13 @@ class _BusinesProfileState extends State<BusinesProfile> {
|
||||||
return Consumer<MzansiProfileProvider>(
|
return Consumer<MzansiProfileProvider>(
|
||||||
builder: (BuildContext context,
|
builder: (BuildContext context,
|
||||||
MzansiProfileProvider mzansiProfileProvider, Widget? child) {
|
MzansiProfileProvider mzansiProfileProvider, Widget? child) {
|
||||||
if (_isLoadingInitialData) {
|
// if (_isLoadingInitialData) {
|
||||||
return Scaffold(
|
// return Scaffold(
|
||||||
body: Center(
|
// body: Center(
|
||||||
child: Mihloadingcircle(),
|
// child: Mihloadingcircle(),
|
||||||
),
|
// ),
|
||||||
);
|
// );
|
||||||
}
|
// }
|
||||||
return MihPackage(
|
return MihPackage(
|
||||||
packageActionButton: getAction(),
|
packageActionButton: getAction(),
|
||||||
packageTools: getTools(),
|
packageTools: getTools(),
|
||||||
|
|
|
||||||
|
|
@ -17,32 +17,32 @@ class MzansiProfile extends StatefulWidget {
|
||||||
}
|
}
|
||||||
|
|
||||||
class _MzansiProfileState extends State<MzansiProfile> {
|
class _MzansiProfileState extends State<MzansiProfile> {
|
||||||
bool _isLoadingInitialData = true;
|
// bool _isLoadingInitialData = true;
|
||||||
late final MihPersonalProfile _personalProfile;
|
late final MihPersonalProfile _personalProfile;
|
||||||
late final MihPersonalQrCode _personalQrCode;
|
late final MihPersonalQrCode _personalQrCode;
|
||||||
late final MihPersonalSettings _personalSettings;
|
late final MihPersonalSettings _personalSettings;
|
||||||
|
|
||||||
Future<void> _loadInitialData() async {
|
// Future<void> _loadInitialData() async {
|
||||||
MzansiProfileProvider mzansiProfileProvider =
|
// MzansiProfileProvider mzansiProfileProvider =
|
||||||
context.read<MzansiProfileProvider>();
|
// context.read<MzansiProfileProvider>();
|
||||||
mzansiProfileProvider.loadCachedProfileState();
|
// if (mzansiProfileProvider.user == null) {
|
||||||
if (mzansiProfileProvider.user == null) {
|
// mzansiProfileProvider.loadCachedProfileState();
|
||||||
mzansiProfileProvider.syncWithCloudPipeline();
|
// mzansiProfileProvider.syncWithMihServerData();
|
||||||
}
|
// }
|
||||||
setState(() {
|
// setState(() {
|
||||||
_isLoadingInitialData = false;
|
// _isLoadingInitialData = false;
|
||||||
});
|
// });
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
_personalProfile = const MihPersonalProfile();
|
_personalProfile = const MihPersonalProfile();
|
||||||
_personalQrCode = const MihPersonalQrCode(user: null);
|
_personalQrCode = const MihPersonalQrCode(user: null);
|
||||||
_personalSettings = const MihPersonalSettings();
|
_personalSettings = const MihPersonalSettings();
|
||||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
// WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
_loadInitialData();
|
// _loadInitialData();
|
||||||
});
|
// });
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|
@ -50,13 +50,13 @@ class _MzansiProfileState extends State<MzansiProfile> {
|
||||||
return Consumer<MzansiProfileProvider>(
|
return Consumer<MzansiProfileProvider>(
|
||||||
builder: (BuildContext context, MzansiProfileProvider profileProvider,
|
builder: (BuildContext context, MzansiProfileProvider profileProvider,
|
||||||
Widget? child) {
|
Widget? child) {
|
||||||
if (_isLoadingInitialData) {
|
// if (_isLoadingInitialData) {
|
||||||
return Scaffold(
|
// return Scaffold(
|
||||||
body: Center(
|
// body: Center(
|
||||||
child: Mihloadingcircle(),
|
// child: Mihloadingcircle(),
|
||||||
),
|
// ),
|
||||||
);
|
// );
|
||||||
}
|
// }
|
||||||
return MihPackage(
|
return MihPackage(
|
||||||
packageActionButton: getAction(),
|
packageActionButton: getAction(),
|
||||||
packageTools: getTools(),
|
packageTools: getTools(),
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
import 'package:cached_network_image/cached_network_image.dart';
|
import 'package:cached_network_image/cached_network_image.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:ken_logger/ken_logger.dart';
|
||||||
import 'package:mzansi_innovation_hub/mih_hive/mzansi_profile_hive_data.dart';
|
import 'package:mzansi_innovation_hub/mih_hive/mzansi_profile_hive_data.dart';
|
||||||
import 'package:mzansi_innovation_hub/mih_objects/app_user.dart';
|
import 'package:mzansi_innovation_hub/mih_objects/app_user.dart';
|
||||||
import 'package:mzansi_innovation_hub/mih_objects/business.dart';
|
import 'package:mzansi_innovation_hub/mih_objects/business.dart';
|
||||||
|
|
@ -29,6 +30,8 @@ class MzansiProfileProvider extends ChangeNotifier {
|
||||||
bool hideBusinessUserDetails;
|
bool hideBusinessUserDetails;
|
||||||
List<ProfileLink> personalLinks = [];
|
List<ProfileLink> personalLinks = [];
|
||||||
List<ProfileLink> businessLinks = [];
|
List<ProfileLink> businessLinks = [];
|
||||||
|
final GlobalKey<RefreshIndicatorState> refreshIndicatorKey =
|
||||||
|
GlobalKey<RefreshIndicatorState>();
|
||||||
|
|
||||||
MzansiProfileProvider(
|
MzansiProfileProvider(
|
||||||
this._hiveData, {
|
this._hiveData, {
|
||||||
|
|
@ -59,16 +62,25 @@ class MzansiProfileProvider extends ChangeNotifier {
|
||||||
businessUserSignature = CachedNetworkImageProvider(cachedSigUrl);
|
businessUserSignature = CachedNetworkImageProvider(cachedSigUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
employeeList = _hiveData.getCachedBusinessEmployees();
|
||||||
|
|
||||||
personalLinks = _hiveData.getCachedPersonalProfileLinks();
|
personalLinks = _hiveData.getCachedPersonalProfileLinks();
|
||||||
|
|
||||||
|
businessLinks = _hiveData.getCachedBusinessProfileLinks();
|
||||||
|
|
||||||
|
KenLogger.success("Mzansi Profile Loaded from Cache");
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> syncWithCloudPipeline() async {
|
Future<void> syncWithMihServerData() async {
|
||||||
await _hiveData.syncProfileDataWithServer();
|
await _hiveData.syncProfileDataWithServer();
|
||||||
loadCachedProfileState();
|
loadCachedProfileState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void triggerRefresh() {
|
||||||
|
refreshIndicatorKey.currentState?.show();
|
||||||
|
}
|
||||||
|
|
||||||
void reset() {
|
void reset() {
|
||||||
personalHome = true;
|
personalHome = true;
|
||||||
personalIndex = 0;
|
personalIndex = 0;
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,19 @@ class MihBusinessEmployeeServices {
|
||||||
return response.statusCode;
|
return response.statusCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<List<BusinessEmployee>> fetchEmployeesV2(String business_id) async {
|
||||||
|
final response = await http.get(Uri.parse(
|
||||||
|
"${AppEnviroment.baseApiUrl}/business-user/employees/${business_id}"));
|
||||||
|
if (response.statusCode == 200) {
|
||||||
|
Iterable l = jsonDecode(response.body);
|
||||||
|
List<BusinessEmployee> employeeList = List<BusinessEmployee>.from(
|
||||||
|
l.map((model) => BusinessEmployee.fromJson(model)));
|
||||||
|
return employeeList;
|
||||||
|
} else {
|
||||||
|
throw Exception('failed to load employees');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Future<int> addEmployee(
|
Future<int> addEmployee(
|
||||||
MzansiProfileProvider provider,
|
MzansiProfileProvider provider,
|
||||||
AppUser newEmployee,
|
AppUser newEmployee,
|
||||||
|
|
|
||||||
|
|
@ -89,6 +89,21 @@ class MihProfileLinksServices {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Future<List<ProfileLink>> getBusinessProfileLinksV2(
|
||||||
|
String business_id,
|
||||||
|
) async {
|
||||||
|
final response = await http.get(Uri.parse(
|
||||||
|
"${AppEnviroment.baseApiUrl}/profile-links/business/$business_id"));
|
||||||
|
if (response.statusCode == 200) {
|
||||||
|
Iterable l = jsonDecode(response.body);
|
||||||
|
List<ProfileLink> myLinks =
|
||||||
|
List<ProfileLink>.from(l.map((model) => ProfileLink.fromJson(model)));
|
||||||
|
return myLinks;
|
||||||
|
} else {
|
||||||
|
throw Exception('failed to fecth user profile links');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static Future<int> deleteProfileLink(
|
static Future<int> deleteProfileLink(
|
||||||
MzansiProfileProvider profileProvider,
|
MzansiProfileProvider profileProvider,
|
||||||
int idprofile_links,
|
int idprofile_links,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue