Compare commits

..

No commits in common. "003c8b7c0d7e9450d17a5d1e6121fef9c1e3c703" and "f19a316be86aa3157612d3d5a81c6a49a827b489" have entirely different histories.

19 changed files with 150 additions and 423 deletions

View file

@ -12,7 +12,6 @@ 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_objects/app_user.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/profile_link.dart';
import 'package:mzansi_innovation_hub/mih_objects/user_consent.dart';
@ -37,8 +36,6 @@ void main() async {
await Hive.openBox<UserConsent>('user_consent_box');
await Hive.openBox<String>('image_urls_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(
// // options: DefaultFirebaseOptions.currentPlatform,

View file

@ -171,7 +171,9 @@ class MihGoRouter {
path: MihGoRouterPaths.mihHome,
builder: (BuildContext context, GoRouterState state) {
KenLogger.success("MihGoRouter: mihHome");
return MihHome();
return MihHome(
key: UniqueKey(),
);
},
routes: [
// ========================== About MIH ==================================

View file

@ -2,7 +2,6 @@
import 'package:hive_ce/hive_ce.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_employee.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/user_consent.dart';
@ -13,6 +12,5 @@ import 'package:mzansi_innovation_hub/mih_objects/user_consent.dart';
AdapterSpec<BusinessUser>(),
AdapterSpec<UserConsent>(),
AdapterSpec<ProfileLink>(),
AdapterSpec<BusinessEmployee>(),
])
part 'hive_adapters.g.dart';

View file

@ -283,58 +283,3 @@ class ProfileLinkAdapter extends TypeAdapter<ProfileLink> {
runtimeType == other.runtimeType &&
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;
}

View file

@ -1,7 +1,7 @@
# Generated by Hive CE
# Manual modifications may be necessary for certain migrations
# Check in to version control
nextTypeId: 6
nextTypeId: 5
types:
AppUser:
typeId: 0
@ -105,23 +105,3 @@ types:
index: 5
order:
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

View file

@ -9,7 +9,6 @@ extension HiveRegistrar on HiveInterface {
void registerAdapters() {
registerAdapter(AppUserAdapter());
registerAdapter(BusinessAdapter());
registerAdapter(BusinessEmployeeAdapter());
registerAdapter(BusinessUserAdapter());
registerAdapter(ProfileLinkAdapter());
registerAdapter(UserConsentAdapter());
@ -20,7 +19,6 @@ extension IsolatedHiveRegistrar on IsolatedHiveInterface {
void registerAdapters() {
registerAdapter(AppUserAdapter());
registerAdapter(BusinessAdapter());
registerAdapter(BusinessEmployeeAdapter());
registerAdapter(BusinessUserAdapter());
registerAdapter(ProfileLinkAdapter());
registerAdapter(UserConsentAdapter());

View file

@ -2,12 +2,10 @@ 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';
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/profile_link.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_employee_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_profile_links_service.dart';
@ -23,10 +21,7 @@ class MzansiProfileHiveData {
Hive.box<UserConsent>('user_consent_box');
final Box<ProfileLink> _personalProfileLinksBox =
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');
static const String kUserKey = 'current_user';
@ -37,7 +32,6 @@ class MzansiProfileHiveData {
static const String kBusinessPicUrlKey = 'business_pic_url';
static const String kSignatureUrlKey = 'signature_url';
// Get Data from local storage
AppUser? getCachedUser() => _userBox.get(kUserKey);
Business? getCachedBusiness() => _businessBox.get(kBusinessKey);
BusinessUser? getCachedBusinessUser() =>
@ -46,26 +40,12 @@ class MzansiProfileHiveData {
String? getCachedUserPicUrl() => _resolvedUrlsBox.get(kUserPicUrlKey);
String? getCachedBusinessPicUrl() => _resolvedUrlsBox.get(kBusinessPicUrlKey);
String? getCachedSignatureUrl() => _resolvedUrlsBox.get(kSignatureUrlKey);
List<ProfileLink> getCachedPersonalProfileLinks() {
final links = _personalProfileLinksBox.values.toList();
links.sort((a, b) => a.order.compareTo(b.order));
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 {
await _userBox.put(kUserKey, remoteUser);
if (remoteUser.pro_pic_path.isNotEmpty) {
@ -73,12 +53,10 @@ class MzansiProfileHiveData {
await MihFileApi.getMinioFileUrl(remoteUser.pro_pic_path);
await _resolvedUrlsBox.put(kUserPicUrlKey, userPicUrl);
}
KenLogger.success("User Profile Cached");
}
Future<void> cacheUserConsentData(UserConsent remoteConsent) async {
await _userConsentBox.put(kConsentKey, remoteConsent);
KenLogger.success("User Consent Cached");
}
Future<void> cacheBusinessData(Business remoteBusiness) async {
@ -93,7 +71,6 @@ class MzansiProfileHiveData {
if (remoteBizUser != null) {
cacheBusinessUserData(remoteBizUser);
}
KenLogger.success("Busines Profile Cached");
}
Future<void> cacheBusinessUserData(BusinessUser remoteBizUser) async {
@ -103,64 +80,36 @@ class MzansiProfileHiveData {
await MihFileApi.getMinioFileUrl(remoteBizUser.sig_path);
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(
List<ProfileLink> remotePersonalLinks) async {
List<ProfileLink> remoteLinks) async {
await _personalProfileLinksBox.clear();
await _personalProfileLinksBox.addAll(remotePersonalLinks);
KenLogger.success("Personal Profile Links Cached");
await _personalProfileLinksBox.addAll(remoteLinks);
}
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<bool> syncProfileDataWithServer() async {
Future<void> syncProfileDataWithServer() async {
try {
AppUser? remoteUser = await MihUserServices().getMyUserDetailsV2();
if (remoteUser != null) {
cacheUserData(remoteUser);
UserConsent? remoteConsent =
await MihUserConsentServices().getUserConsentStatusV2();
if (remoteConsent != null) {
cacheUserConsentData(remoteConsent);
}
final remotePersonalLinks =
await MihProfileLinksServices.getUserProfileLinksV2(
remoteUser.app_id);
cachePersonalProfileLinksData(remotePersonalLinks);
final remoteLinks = await MihProfileLinksServices.getUserProfileLinksV2(
remoteUser.app_id);
await cachePersonalProfileLinksData(remoteLinks);
}
Business? remoteBusiness =
await MihBusinessDetailsServices().getBusinessDetailsByUserV2();
if (remoteBusiness != null) {
cacheBusinessData(remoteBusiness);
final remoteBusinessEmployeeList = await MihBusinessEmployeeServices()
.fetchEmployeesV2(remoteBusiness.business_id);
cacheBusinessEmployeesData(remoteBusinessEmployeeList);
final remoteBusinessLinks =
await MihProfileLinksServices.getBusinessProfileLinksV2(
remoteBusiness.business_id);
cacheBusinessProfileLinksData(remoteBusinessLinks);
}
return true;
} catch (error) {
KenLogger.warning("App Operating in Offline Mode. Sync Paused");
return false;
KenLogger.warning("App operating offline mode. Sync paused");
// KenLogger.warning("App operating offline mode. Sync paused: $error");
}
}

View file

@ -42,11 +42,9 @@ class _MihHomeState extends State<MihHome> {
context.read<MzansiProfileProvider>();
mzansiProfileProvider.loadCachedProfileState();
if (mzansiProfileProvider.user == null) {
await mzansiProfileProvider.syncWithMihServerData();
} else {
mzansiProfileProvider.syncWithMihServerData();
await mzansiProfileProvider.syncWithCloudPipeline();
}
}
}
@override
void dispose() {
@ -76,32 +74,18 @@ class _MihHomeState extends State<MihHome> {
return Consumer<MzansiProfileProvider>(
builder: (BuildContext context,
MzansiProfileProvider mzansiProfileProvider, Widget? child) {
if (mzansiProfileProvider.user == null) {
return Scaffold(
body: Center(
child: Mihloadingcircle(),
),
);
}
if (mzansiProfileProvider.user == null) {
return Scaffold(
body: Center(
child: Mihloadingcircle(),
),
);
}
return Stack(
children: [
RefreshIndicator(
key: mzansiProfileProvider.refreshIndicatorKey,
onRefresh: () async {
bool success =
await mzansiProfileProvider.syncWithMihServerData();
if (context.mounted) {
ScaffoldMessenger.of(context).showSnackBar(
MihSnackBar(
child: Text(
success
? "Data Synced with MIH Server."
: "MIH App operation in Offline Mode",
),
// backgroundColor: success ? null : MihColors.red(),
),
);
}
await mzansiProfileProvider.syncWithCloudPipeline();
},
child: SingleChildScrollView(
physics: const AlwaysScrollableScrollPhysics(),

View file

@ -1,51 +0,0 @@
import 'package:flutter/material.dart';
import 'package:mih_package_toolkit/mih_package_toolkit.dart';
import 'package:mzansi_innovation_hub/mih_providers/mzansi_profile_provider.dart';
import 'package:provider/provider.dart';
class MihHomeRefreshTile extends StatefulWidget {
final double packageSize;
const MihHomeRefreshTile({
super.key,
required this.packageSize,
});
@override
State<MihHomeRefreshTile> createState() => _MihHomeRefreshTileState();
}
class _MihHomeRefreshTileState extends State<MihHomeRefreshTile> {
@override
Widget build(BuildContext context) {
return Consumer<MzansiProfileProvider>(
builder: (BuildContext context, MzansiProfileProvider profileProvider,
Widget? child) {
return MihPackageTile(
onTap: profileProvider.triggerRefresh,
packageName: "Sync Data",
packageIcon: Stack(
alignment: Alignment.center,
children: [
Icon(
MihIcons.mihRing,
color: MihColors.secondary(),
),
Center(
child: Transform.scale(
scale: 0.75,
origin: Offset(-4, 0),
child: Icon(
Icons.cloud_sync_rounded,
color: MihColors.secondary(),
),
),
),
],
),
iconSize: widget.packageSize,
textColor: MihColors.secondary(),
);
},
);
}
}

View file

@ -2,7 +2,6 @@ import 'package:go_router/go_router.dart';
import 'package:mih_package_toolkit/mih_package_toolkit.dart';
import 'package:mzansi_innovation_hub/main.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_profile_provider.dart';
import 'package:mzansi_innovation_hub/mih_packages/about_mih/package_tile/about_mih_tile.dart';
@ -130,12 +129,6 @@ class _MihBusinessHomeState extends State<MihBusinessHome>
packageSize: packageSize,
)
});
//=============== About MIH ===============
temp.add({
"Sync Data": MihHomeRefreshTile(
packageSize: packageSize,
)
});
return temp;
}

View file

@ -3,7 +3,6 @@ import 'package:mih_package_toolkit/mih_package_toolkit.dart';
import 'package:mzansi_innovation_hub/main.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_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_providers/mzansi_ai_provider.dart';
import 'package:mzansi_innovation_hub/mih_packages/about_mih/package_tile/about_mih_tile.dart';
@ -139,12 +138,6 @@ class _MihPersonalHomeState extends State<MihPersonalHome>
packageSize: packageSize,
)
});
//=============== About MIH ===============
temp.add({
"Sync Data": MihHomeRefreshTile(
packageSize: packageSize,
)
});
//=============== Dev ===============
if (AppEnviroment.getEnv() == "Dev") {
temp.add({

View file

@ -22,7 +22,7 @@ class BusinesProfile extends StatefulWidget {
}
class _BusinesProfileState extends State<BusinesProfile> {
// bool _isLoadingInitialData = true;
bool _isLoadingInitialData = true;
late final MihBusinessDetails _businessDetails;
late final MihMyBusinessUser _businessUser;
late final MihMyBusinessTeam _businessTeam;
@ -31,18 +31,26 @@ class _BusinesProfileState extends State<BusinesProfile> {
late final MihBusinessQrCode _businessQrCode;
late final MihBusinessLinks _businessLinks;
// Future<void> _loadInitialData() async {
// MzansiProfileProvider mzansiProfileProvider =
// context.read<MzansiProfileProvider>();
// mzansiProfileProvider.loadCachedProfileState();
// if (mzansiProfileProvider.user == null) {
// mzansiProfileProvider.syncWithMihServerData();
// }
// setState(() {
// _isLoadingInitialData = false;
// });
// }
//
Future<void> _loadInitialData() async {
setState(() {
_isLoadingInitialData = true;
});
MzansiProfileProvider mzansiProfileProvider =
context.read<MzansiProfileProvider>();
if (mzansiProfileProvider.user == null) {
await MihDataHelperServices().loadUserDataWithBusinessesData(
mzansiProfileProvider,
);
}
await MihProfileLinksServices.getBusinessProfileLinks(
mzansiProfileProvider, mzansiProfileProvider.business!.business_id);
await MihBusinessEmployeeServices()
.fetchEmployees(mzansiProfileProvider, context);
setState(() {
_isLoadingInitialData = false;
});
}
@override
void initState() {
super.initState();
@ -53,7 +61,7 @@ class _BusinesProfileState extends State<BusinesProfile> {
_businessReviews = MihBusinessReviews(business: null);
_businessLinks = MihBusinessLinks(viewMode: false);
_businessQrCode = MihBusinessQrCode(business: null);
// _loadInitialData();
_loadInitialData();
}
@override
@ -61,13 +69,13 @@ class _BusinesProfileState extends State<BusinesProfile> {
return Consumer<MzansiProfileProvider>(
builder: (BuildContext context,
MzansiProfileProvider mzansiProfileProvider, Widget? child) {
// if (_isLoadingInitialData) {
// return Scaffold(
// body: Center(
// child: Mihloadingcircle(),
// ),
// );
// }
if (_isLoadingInitialData) {
return Scaffold(
body: Center(
child: Mihloadingcircle(),
),
);
}
return MihPackage(
packageActionButton: getAction(),
packageTools: getTools(),

View file

@ -175,8 +175,6 @@ class _MihBusinessQrCodeState extends State<MihBusinessQrCode> {
}
Widget displayBusinessQRCode(double profilePictureWidth) {
MzansiProfileProvider profileprovider =
context.read<MzansiProfileProvider>();
return Screenshot(
controller: screenshotController,
child: Material(
@ -195,54 +193,42 @@ class _MihBusinessQrCodeState extends State<MihBusinessQrCode> {
mainAxisAlignment: MainAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
widget.business == null
? MihCircleAvatar(
imageFile: profileprovider.businessProfilePicture,
width: profilePictureWidth,
expandable: true,
editable: false,
fileNameController: TextEditingController(),
userSelectedfile: file,
frameColor: MihColors.primary(),
backgroundColor: MihColors.secondary(),
onChange: () {},
)
: FutureBuilder(
future: futureImageUrl,
builder: (context, asyncSnapshot) {
if (asyncSnapshot.connectionState ==
ConnectionState.done &&
asyncSnapshot.hasData) {
if (asyncSnapshot.requireData != "" ||
asyncSnapshot.requireData.isNotEmpty) {
return MihCircleAvatar(
imageFile: CachedNetworkImageProvider(
asyncSnapshot.requireData),
width: profilePictureWidth,
expandable: true,
editable: false,
fileNameController: TextEditingController(),
userSelectedfile: file,
frameColor: MihColors.primary(),
backgroundColor: MihColors.secondary(),
onChange: () {},
);
} else {
return Icon(
MihIcons.mihIDontKnow,
size: profilePictureWidth,
color: MihColors.primary(),
);
}
} else {
return Icon(
MihIcons.mihRing,
size: profilePictureWidth,
color: MihColors.primary(),
);
}
},
),
FutureBuilder(
future: futureImageUrl,
builder: (context, asyncSnapshot) {
if (asyncSnapshot.connectionState ==
ConnectionState.done &&
asyncSnapshot.hasData) {
if (asyncSnapshot.requireData != "" ||
asyncSnapshot.requireData.isNotEmpty) {
return MihCircleAvatar(
imageFile: CachedNetworkImageProvider(
asyncSnapshot.requireData),
width: profilePictureWidth,
expandable: true,
editable: false,
fileNameController: TextEditingController(),
userSelectedfile: file,
frameColor: MihColors.primary(),
backgroundColor: MihColors.secondary(),
onChange: () {},
);
} else {
return Icon(
MihIcons.mihIDontKnow,
size: profilePictureWidth,
color: MihColors.primary(),
);
}
} else {
return Icon(
MihIcons.mihRing,
size: profilePictureWidth,
color: MihColors.primary(),
);
}
},
),
FittedBox(
child: Text(
business.Name,

View file

@ -231,7 +231,7 @@ class _MihBusinessReviewsState extends State<MihBusinessReviews> {
);
}
} else {
return Center(child: Text('Error: MIH in Offline Mode'));
return Center(child: Text('Error'));
}
});
}

View file

@ -17,32 +17,32 @@ class MzansiProfile extends StatefulWidget {
}
class _MzansiProfileState extends State<MzansiProfile> {
// bool _isLoadingInitialData = true;
bool _isLoadingInitialData = true;
late final MihPersonalProfile _personalProfile;
late final MihPersonalQrCode _personalQrCode;
late final MihPersonalSettings _personalSettings;
// Future<void> _loadInitialData() async {
// MzansiProfileProvider mzansiProfileProvider =
// context.read<MzansiProfileProvider>();
// if (mzansiProfileProvider.user == null) {
// mzansiProfileProvider.loadCachedProfileState();
// mzansiProfileProvider.syncWithMihServerData();
// }
// setState(() {
// _isLoadingInitialData = false;
// });
// }
//
Future<void> _loadInitialData() async {
MzansiProfileProvider mzansiProfileProvider =
context.read<MzansiProfileProvider>();
mzansiProfileProvider.loadCachedProfileState();
if (mzansiProfileProvider.user == null) {
mzansiProfileProvider.syncWithCloudPipeline();
}
setState(() {
_isLoadingInitialData = false;
});
}
@override
void initState() {
super.initState();
_personalProfile = const MihPersonalProfile();
_personalQrCode = const MihPersonalQrCode(user: null);
_personalSettings = const MihPersonalSettings();
// WidgetsBinding.instance.addPostFrameCallback((_) {
// _loadInitialData();
// });
WidgetsBinding.instance.addPostFrameCallback((_) {
_loadInitialData();
});
}
@override
@ -50,13 +50,13 @@ class _MzansiProfileState extends State<MzansiProfile> {
return Consumer<MzansiProfileProvider>(
builder: (BuildContext context, MzansiProfileProvider profileProvider,
Widget? child) {
// if (_isLoadingInitialData) {
// return Scaffold(
// body: Center(
// child: Mihloadingcircle(),
// ),
// );
// }
if (_isLoadingInitialData) {
return Scaffold(
body: Center(
child: Mihloadingcircle(),
),
);
}
return MihPackage(
packageActionButton: getAction(),
packageTools: getTools(),

View file

@ -174,8 +174,6 @@ class _MihPersonalQrCodeState extends State<MihPersonalQrCode> {
}
Widget displayPersonalQRCode(double profilePictureWidth) {
MzansiProfileProvider profileProvider =
context.read<MzansiProfileProvider>();
return Screenshot(
controller: screenshotController,
child: Material(
@ -194,54 +192,42 @@ class _MihPersonalQrCodeState extends State<MihPersonalQrCode> {
mainAxisAlignment: MainAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
widget.user == null
? MihCircleAvatar(
imageFile: profileProvider.userProfilePicture,
width: profilePictureWidth,
expandable: true,
editable: false,
fileNameController: TextEditingController(),
userSelectedfile: file,
frameColor: MihColors.primary(),
backgroundColor: MihColors.secondary(),
onChange: () {},
)
: FutureBuilder(
future: futureImageUrl,
builder: (context, asyncSnapshot) {
if (asyncSnapshot.connectionState ==
ConnectionState.done &&
asyncSnapshot.hasData) {
if (asyncSnapshot.requireData != "" ||
asyncSnapshot.requireData.isNotEmpty) {
return MihCircleAvatar(
imageFile: CachedNetworkImageProvider(
asyncSnapshot.requireData),
width: profilePictureWidth,
expandable: true,
editable: false,
fileNameController: TextEditingController(),
userSelectedfile: file,
frameColor: MihColors.primary(),
backgroundColor: MihColors.secondary(),
onChange: () {},
);
} else {
return Icon(
MihIcons.mihIDontKnow,
size: profilePictureWidth,
color: MihColors.primary(),
);
}
} else {
return Icon(
MihIcons.mihRing,
size: profilePictureWidth,
color: MihColors.primary(),
);
}
},
),
FutureBuilder(
future: futureImageUrl,
builder: (context, asyncSnapshot) {
if (asyncSnapshot.connectionState ==
ConnectionState.done &&
asyncSnapshot.hasData) {
if (asyncSnapshot.requireData != "" ||
asyncSnapshot.requireData.isNotEmpty) {
return MihCircleAvatar(
imageFile: CachedNetworkImageProvider(
asyncSnapshot.requireData),
width: profilePictureWidth,
expandable: true,
editable: false,
fileNameController: TextEditingController(),
userSelectedfile: file,
frameColor: MihColors.primary(),
backgroundColor: MihColors.secondary(),
onChange: () {},
);
} else {
return Icon(
MihIcons.mihIDontKnow,
size: profilePictureWidth,
color: MihColors.primary(),
);
}
} else {
return Icon(
MihIcons.mihRing,
size: profilePictureWidth,
color: MihColors.primary(),
);
}
},
),
FittedBox(
child: Text(
user.username,

View file

@ -1,6 +1,5 @@
import 'package:cached_network_image/cached_network_image.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_objects/app_user.dart';
import 'package:mzansi_innovation_hub/mih_objects/business.dart';
@ -30,8 +29,6 @@ class MzansiProfileProvider extends ChangeNotifier {
bool hideBusinessUserDetails;
List<ProfileLink> personalLinks = [];
List<ProfileLink> businessLinks = [];
final GlobalKey<RefreshIndicatorState> refreshIndicatorKey =
GlobalKey<RefreshIndicatorState>();
MzansiProfileProvider(
this._hiveData, {
@ -62,24 +59,14 @@ class MzansiProfileProvider extends ChangeNotifier {
businessUserSignature = CachedNetworkImageProvider(cachedSigUrl);
}
employeeList = _hiveData.getCachedBusinessEmployees();
personalLinks = _hiveData.getCachedPersonalProfileLinks();
businessLinks = _hiveData.getCachedBusinessProfileLinks();
KenLogger.success("Mzansi Profile Loaded from Cache");
notifyListeners();
}
Future<bool> syncWithMihServerData() async {
bool success = await _hiveData.syncProfileDataWithServer();
Future<void> syncWithCloudPipeline() async {
await _hiveData.syncProfileDataWithServer();
loadCachedProfileState();
return success;
}
void triggerRefresh() {
refreshIndicatorKey.currentState?.show();
}
void reset() {

View file

@ -25,19 +25,6 @@ class MihBusinessEmployeeServices {
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(
MzansiProfileProvider provider,
AppUser newEmployee,

View file

@ -89,21 +89,6 @@ 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(
MzansiProfileProvider profileProvider,
int idprofile_links,