NEW: MIH Home & Mzansi Profile Provider Setup pt 2 done

This commit is contained in:
2025-10-20 16:41:24 +02:00
parent c89932755f
commit 2e69e1dd92
25 changed files with 1937 additions and 1653 deletions

View File

@@ -39,7 +39,6 @@ class MihHome extends StatefulWidget {
}
class _MihHomeState extends State<MihHome> {
final proPicController = TextEditingController();
late int _selcetedIndex;
late bool _personalHome;
DateTime latestPrivacyPolicyDate = DateTime.parse("2024-12-01");
@@ -47,11 +46,30 @@ class _MihHomeState extends State<MihHome> {
bool _isLoadingInitialData = true;
Future<void> _loadInitialData() async {
if (mounted) {
setState(() {
_isLoadingInitialData = true;
});
}
MzansiProfileProvider mzansiProfileProvider =
context.read<MzansiProfileProvider>();
// Note: getUserData sets user and userProfilePicUrl in the provider
await getUserData();
if (mzansiProfileProvider.user == null) {
await getUserData();
}
// Note: getUserConsentStatus sets userConsent in the provider
await getUserConsentStatus();
await getBusinessData();
if (mzansiProfileProvider.userConsent == null) {
await getUserConsentStatus();
}
// 1. Get Business Data
if (mzansiProfileProvider.user != null &&
mzansiProfileProvider.user!.type == "business" &&
mzansiProfileProvider.business == null) {
KenLogger.success(mzansiProfileProvider.business == null
? "Business is null, fetching business data..."
: "Business data already loaded.");
await getBusinessData();
}
// 2. Set state after all data is loaded
if (mounted) {
setState(() {
@@ -61,13 +79,23 @@ class _MihHomeState extends State<MihHome> {
}
Future<void> getBusinessData() async {
Business? business = context.read<MzansiProfileProvider>().business;
AppUser? user = context.read<MzansiProfileProvider>().user;
String logoUrl;
String signatureUrl;
if (business == null && user!.type == "business") {
Business? responseBusiness =
await MihBusinessDetailsServices().getBusinessDetailsByUser(context);
if (responseBusiness == null && user!.type == "business") {
if (mounted) {
context.goNamed(
'businessProfileSetup',
extra: user,
);
}
}
if (responseBusiness != null && user!.type == "business") {
// Get Business
await MihBusinessDetailsServices().getBusinessDetailsByUser(context);
// Business Profile Set Up aleary
logoUrl = await MihFileApi.getMinioFileUrl(
context.read<MzansiProfileProvider>().business!.logo_path,
context,
@@ -152,10 +180,12 @@ class _MihHomeState extends State<MihHome> {
}
Future<void> getUserData() async {
if (!mounted) return;
String url;
await MihUserServices().getUserDetails(
context,
);
if (!mounted) return;
url = await MihFileApi.getMinioFileUrl(
context.read<MzansiProfileProvider>().user!.pro_pic_path,
context,
@@ -164,6 +194,7 @@ class _MihHomeState extends State<MihHome> {
}
Future<void> getUserConsentStatus() async {
if (!mounted) return;
await MihUserConsentServices().getUserConsentStatus(context);
}
@@ -175,9 +206,6 @@ class _MihHomeState extends State<MihHome> {
@override
void initState() {
super.initState();
WidgetsBinding.instance.addPostFrameCallback((_) async {
_loadInitialData();
});
if (context.read<MzansiProfileProvider>().personalHome == true) {
_selcetedIndex = 0;
_personalHome = true;
@@ -185,6 +213,7 @@ class _MihHomeState extends State<MihHome> {
_selcetedIndex = 1;
_personalHome = false;
}
_loadInitialData();
}
List<String> getToolTitle() {
@@ -211,28 +240,39 @@ class _MihHomeState extends State<MihHome> {
// showPolicyWindow(mzansiProfileProvider.userConsent);
return Stack(
children: [
MihPackage(
appActionButton:
getAction(mzansiProfileProvider.userProfilePicUrl as String),
appTools:
getTools(mzansiProfileProvider.user!.type != "personal"),
appBody: getToolBody(),
appToolTitles: getToolTitle(),
actionDrawer: getActionDrawer(),
selectedbodyIndex: _selcetedIndex,
onIndexChange: (newValue) {
if (_selcetedIndex == 0) {
setState(() {
_selcetedIndex = newValue;
_personalHome = true;
});
} else {
setState(() {
_selcetedIndex = newValue;
_personalHome = false;
});
}
RefreshIndicator(
onRefresh: () async {
await _loadInitialData();
},
child: SingleChildScrollView(
physics: const AlwaysScrollableScrollPhysics(),
child: SizedBox(
height: MediaQuery.of(context).size.height,
child: MihPackage(
appActionButton: getAction(
mzansiProfileProvider.userProfilePicUrl as String),
appTools: getTools(
mzansiProfileProvider.user!.type != "personal"),
appBody: getToolBody(),
appToolTitles: getToolTitle(),
actionDrawer: getActionDrawer(),
selectedbodyIndex: _selcetedIndex,
onIndexChange: (newValue) {
if (_selcetedIndex == 0) {
setState(() {
_selcetedIndex = newValue;
_personalHome = true;
});
} else {
setState(() {
_selcetedIndex = newValue;
_personalHome = false;
});
}
},
),
),
),
),
Visibility(
visible: showPolicyWindow(mzansiProfileProvider.userConsent),
@@ -443,7 +483,7 @@ class _MihHomeState extends State<MihHome> {
imageFile: proPicUrl != "" ? NetworkImage(proPicUrl) : null,
width: 50,
editable: false,
fileNameController: proPicController,
fileNameController: null,
userSelectedfile: null,
// frameColor: frameColor,
frameColor: MihColors.getSecondaryColor(
@@ -452,17 +492,6 @@ class _MihHomeState extends State<MihHome> {
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
onChange: (_) {},
),
// MIHProfilePicture(
// profilePictureFile: widget.propicFile,
// proPicController: proPicController,
// proPic: null,
// width: 45,
// radius: 21,
// drawerMode: false,
// editable: false,
// frameColor: MihColors.getSecondaryColor(MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
// onChange: (newProPic) {},
// ),
),
iconSize: 45,
onTap: () {
@@ -531,13 +560,7 @@ class _MihHomeState extends State<MihHome> {
);
if (user.type != "personal") {
toolBodies.add(
MihBusinessHome(
signedInUser: user,
personalSelected: _personalHome,
businessUser: businessUser,
business: business,
isBusinessUserNew: businessUser == null,
),
MihBusinessHome(),
);
}
return toolBodies;

View File

@@ -4,10 +4,9 @@ import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_
import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_icons.dart';
import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_package_tool_body.dart';
import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_search_bar.dart';
import 'package:mzansi_innovation_hub/mih_components/mih_objects/app_user.dart';
import 'package:mzansi_innovation_hub/mih_components/mih_objects/arguments.dart';
import 'package:mzansi_innovation_hub/mih_components/mih_objects/business.dart';
import 'package:mzansi_innovation_hub/mih_components/mih_objects/business_user.dart';
import 'package:mzansi_innovation_hub/mih_components/mih_pop_up_messages/mih_loading_circle.dart';
import 'package:mzansi_innovation_hub/mih_components/mih_providers/mzansi_profile_provider.dart';
import 'package:mzansi_innovation_hub/mih_config/mih_colors.dart';
import 'package:mzansi_innovation_hub/mih_packages/about_mih/package_tile/about_mih_tile.dart';
import 'package:mzansi_innovation_hub/mih_packages/calculator/package_tiles/mih_calculator_tile.dart';
@@ -18,20 +17,11 @@ import 'package:mzansi_innovation_hub/mih_packages/mzansi_profile/business_profi
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/patient_profile/pat_manager/package_tiles/pat_manager_tile.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
class MihBusinessHome extends StatefulWidget {
final AppUser signedInUser;
final bool personalSelected;
final Business? business;
final BusinessUser? businessUser;
final bool isBusinessUserNew;
const MihBusinessHome({
super.key,
required this.signedInUser,
required this.personalSelected,
required this.business,
required this.businessUser,
required this.isBusinessUserNew,
});
@override
@@ -70,7 +60,7 @@ class _MihBusinessHomeState extends State<MihBusinessHome>
List<Map<String, Widget>> temp = [];
temp.add({
"Setup Business": MzansiSetupBusinessProfileTile(
signedInUser: widget.signedInUser,
signedInUser: context.read<MzansiProfileProvider>().user!,
packageSize: packageSize,
)
});
@@ -78,15 +68,17 @@ class _MihBusinessHomeState extends State<MihBusinessHome>
}
List<Map<String, Widget>> setBusinessPackages() {
MzansiProfileProvider mzansiProfileProvider =
context.read<MzansiProfileProvider>();
if (mzansiProfileProvider.user == null ||
mzansiProfileProvider.business == null ||
mzansiProfileProvider.businessUser == null) {
return []; // Return empty list if data isn't ready
}
List<Map<String, Widget>> temp = [];
//=============== Biz Profile ===============
temp.add({
"Business Profile": MzansiBusinessProfileTile(
arguments: BusinessArguments(
widget.signedInUser,
widget.businessUser,
widget.business,
),
packageSize: packageSize,
)
});
@@ -94,10 +86,10 @@ class _MihBusinessHomeState extends State<MihBusinessHome>
temp.add({
"Patient Manager": PatManagerTile(
arguments: PatManagerArguments(
widget.signedInUser,
mzansiProfileProvider.user!,
false,
widget.business,
widget.businessUser,
mzansiProfileProvider.business!,
mzansiProfileProvider.businessUser!,
),
packageSize: packageSize,
)
@@ -106,10 +98,10 @@ class _MihBusinessHomeState extends State<MihBusinessHome>
temp.add({
"Calendar": MzansiCalendarTile(
arguments: CalendarArguments(
widget.signedInUser,
mzansiProfileProvider.user!,
false,
widget.business,
widget.businessUser,
mzansiProfileProvider.business!,
mzansiProfileProvider.businessUser!,
),
packageSize: packageSize,
)
@@ -124,7 +116,7 @@ class _MihBusinessHomeState extends State<MihBusinessHome>
//=============== Calculator ===============
temp.add({
"Calculator": MihCalculatorTile(
personalSelected: widget.personalSelected,
personalSelected: mzansiProfileProvider.personalHome,
packageSize: packageSize,
)
});
@@ -132,7 +124,7 @@ class _MihBusinessHomeState extends State<MihBusinessHome>
temp.add({
"Mzansi AI": MzansiAiTile(
arguments: MzansiAiArguments(
widget.signedInUser,
mzansiProfileProvider.user!,
"",
false,
),
@@ -194,19 +186,11 @@ class _MihBusinessHomeState extends State<MihBusinessHome>
void initState() {
super.initState();
searchController.addListener(searchPackage);
if (widget.isBusinessUserNew) {
businessPackagesMap = setNewBusinessUserPackages();
} else {
WidgetsBinding.instance.addPostFrameCallback((_) {
businessPackagesMap = setBusinessPackages();
}
searchPackage();
//Scrolling Banner message
// _marqueeController = AnimationController(
// vsync: this,
// duration: const Duration(seconds: 12),
// );
// _scrollController = ScrollController();
// WidgetsBinding.instance.addPostFrameCallback((_) => _startMarquee());
searchPackage();
});
}
@override
@@ -221,123 +205,113 @@ class _MihBusinessHomeState extends State<MihBusinessHome>
}
Widget getBody(double width, double height) {
return MihSingleChildScroll(
child: Column(
children: [
// Icon(
// MihIcons.mihLogo,
// size: width / 2,
// color: MihColors.getSecondaryColor(MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
// ),
// const SizedBox(height: 10),
// Text(
// // "Welcome, ${widget.signedInUser.fname}!",
// "Mzansi Innovation Hub",
// textAlign: TextAlign.center,
// style: TextStyle(
// fontSize: 30,
// fontWeight: FontWeight.bold,
// color: MihColors.getSecondaryColor(MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
// ),
// ),
// const SizedBox(height: 20),
Visibility(
visible: !widget.isBusinessUserNew,
child: Padding(
padding: EdgeInsets.symmetric(horizontal: width / 20),
child: MihSearchBar(
controller: searchController,
hintText: "Ask Mzansi",
prefixIcon: Icons.search,
prefixAltIcon: MihIcons.mzansiAi,
fillColor: MihColors.getSecondaryColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
hintColor: MihColors.getPrimaryColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
onPrefixIconTap: () {
context.goNamed(
"mzansiAi",
extra: MzansiAiArguments(
widget.signedInUser,
searchController.text.isEmpty
? null
: searchController.text,
false,
),
);
// Navigator.of(context).pushNamed(
// '/mzansi-ai',
// arguments: MzansiAiArguments(
// widget.signedInUser,
// searchController.text.isEmpty
// ? null
// : searchController.text,
// ),
// );
searchController.clear();
},
searchFocusNode: _searchFocusNode,
),
),
),
const SizedBox(height: 20),
ValueListenableBuilder(
valueListenable: searchPackageName,
builder: (context, value, child) {
List<Widget> filteredPackages = value
.where((package) => package.keys.first
.toLowerCase()
.contains(searchController.text.toLowerCase()))
.map((package) => package.values.first)
.toList();
if (filteredPackages.isNotEmpty) {
return GridView.builder(
physics: const NeverScrollableScrollPhysics(),
shrinkWrap: true,
padding: getPadding(width, height),
// shrinkWrap: true,
itemCount: filteredPackages.length,
gridDelegate: SliverGridDelegateWithMaxCrossAxisExtent(
maxCrossAxisExtent: packageSize,
crossAxisSpacing: 5,
),
itemBuilder: (context, index) {
return filteredPackages[index];
},
);
} else {
return Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
const SizedBox(height: 50),
Icon(
MihIcons.mzansiAi,
size: 165,
color: MihColors.getSecondaryColor(
MzansiInnovationHub.of(context)!.theme.mode ==
"Dark"),
),
const SizedBox(height: 10),
Text(
"Mzansi AI is here to help you!",
textAlign: TextAlign.center,
overflow: TextOverflow.visible,
style: TextStyle(
fontSize: 25,
fontWeight: FontWeight.bold,
color: MihColors.getSecondaryColor(
MzansiInnovationHub.of(context)!.theme.mode ==
"Dark"),
return Consumer<MzansiProfileProvider>(
builder: (BuildContext context,
MzansiProfileProvider mzansiProfileProvider, Widget? child) {
if (mzansiProfileProvider.business == null) {
return Center(
child: Mihloadingcircle(),
);
}
return MihSingleChildScroll(
child: Column(
children: [
Padding(
padding: EdgeInsets.symmetric(horizontal: width / 20),
child: MihSearchBar(
controller: searchController,
hintText: "Ask Mzansi",
prefixIcon: Icons.search,
prefixAltIcon: MihIcons.mzansiAi,
fillColor: MihColors.getSecondaryColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
hintColor: MihColors.getPrimaryColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
onPrefixIconTap: () {
context.goNamed(
"mzansiAi",
extra: MzansiAiArguments(
mzansiProfileProvider.user!,
searchController.text.isEmpty
? null
: searchController.text,
false,
),
),
],
);
}
},
);
// Navigator.of(context).pushNamed(
// '/mzansi-ai',
// arguments: MzansiAiArguments(
// widget.signedInUser,
// searchController.text.isEmpty
// ? null
// : searchController.text,
// ),
// );
searchController.clear();
},
searchFocusNode: _searchFocusNode,
),
),
const SizedBox(height: 20),
ValueListenableBuilder(
valueListenable: searchPackageName,
builder: (context, value, child) {
List<Widget> filteredPackages = value
.where((package) => package.keys.first
.toLowerCase()
.contains(searchController.text.toLowerCase()))
.map((package) => package.values.first)
.toList();
if (filteredPackages.isNotEmpty) {
return GridView.builder(
physics: const NeverScrollableScrollPhysics(),
shrinkWrap: true,
padding: getPadding(width, height),
// shrinkWrap: true,
itemCount: filteredPackages.length,
gridDelegate: SliverGridDelegateWithMaxCrossAxisExtent(
maxCrossAxisExtent: packageSize,
crossAxisSpacing: 5,
),
itemBuilder: (context, index) {
return filteredPackages[index];
},
);
} else {
return Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
const SizedBox(height: 50),
Icon(
MihIcons.mzansiAi,
size: 165,
color: MihColors.getSecondaryColor(
MzansiInnovationHub.of(context)!.theme.mode ==
"Dark"),
),
const SizedBox(height: 10),
Text(
"Mzansi AI is here to help you!",
textAlign: TextAlign.center,
overflow: TextOverflow.visible,
style: TextStyle(
fontSize: 25,
fontWeight: FontWeight.bold,
color: MihColors.getSecondaryColor(
MzansiInnovationHub.of(context)!.theme.mode ==
"Dark"),
),
),
],
);
}
},
),
],
),
],
),
);
},
);
}
}