NEW: fix home nav

This commit is contained in:
2025-10-21 09:53:37 +02:00
parent 2e69e1dd92
commit 15106d0a00
14 changed files with 138 additions and 149 deletions

View File

@@ -43,6 +43,11 @@ class MzansiProfileProvider extends ChangeNotifier {
userConsent = null;
}
void setPersonalHome(bool isPersonalHome) {
personalHome = isPersonalHome;
notifyListeners();
}
void setPersonalIndex(int index) {
personalIndex = index;
notifyListeners();

View File

@@ -146,12 +146,7 @@ class MihGoRouter {
path: MihGoRouterPaths.aboutMih,
builder: (BuildContext context, GoRouterState state) {
KenLogger.success("MihGoRouter: aboutMih");
final bool? args = state.extra as bool?;
bool personalSelected = true;
if (args != null) {
personalSelected = args;
}
return AboutMih(personalSelected: personalSelected);
return AboutMih();
},
),
// ========================== Mzansi Profile Personal ==================================
@@ -237,12 +232,7 @@ class MihGoRouter {
path: MihGoRouterPaths.calculator,
builder: (BuildContext context, GoRouterState state) {
KenLogger.success("MihGoRouter: mihCalculator");
final bool? personalSelected = state.extra as bool?;
bool personal = true;
if (personalSelected != null) {
personal = personalSelected;
}
return MIHCalculator(personalSelected: personal);
return MIHCalculator();
},
),
// ========================== MIH Calculator ==================================

View File

@@ -11,12 +11,8 @@ import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
class AboutMih extends StatefulWidget {
final bool? personalSelected;
// final AboutArguments? arguments;
const AboutMih({
super.key,
// this.arguments,
this.personalSelected,
});
@override
@@ -24,18 +20,9 @@ class AboutMih extends StatefulWidget {
}
class _AboutMihState extends State<AboutMih> {
late bool _personalSelected;
@override
void initState() {
super.initState();
setState(() {
if (widget.personalSelected == null) {
_personalSelected = true;
} else {
_personalSelected = widget.personalSelected!;
}
});
}
@override
@@ -59,7 +46,6 @@ class _AboutMihState extends State<AboutMih> {
onTap: () {
context.goNamed(
'mihHome',
extra: _personalSelected,
);
FocusScope.of(context).unfocus();
},

View File

@@ -43,7 +43,6 @@ class _MihAccessState extends State<MihAccess> {
onTap: () {
context.goNamed(
'mihHome',
extra: true,
);
FocusScope.of(context).unfocus();
},

View File

@@ -12,10 +12,8 @@ import 'package:mzansi_innovation_hub/mih_services/mih_currency_exchange_rate_se
import 'package:provider/provider.dart';
class MIHCalculator extends StatefulWidget {
final bool personalSelected;
const MIHCalculator({
super.key,
required this.personalSelected,
});
@override
@@ -57,7 +55,6 @@ class _MIHCalculatorState extends State<MIHCalculator> {
onTap: () {
context.goNamed(
'mihHome',
extra: widget.personalSelected,
);
FocusScope.of(context).unfocus();
},

View File

@@ -1,6 +1,5 @@
import 'package:flutter/material.dart';
import 'package:go_router/go_router.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_package_components/mih_circle_avatar.dart';
import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_icons.dart';
@@ -12,13 +11,8 @@ import '../../../main.dart';
import 'package:supertokens_flutter/supertokens.dart';
class MIHAppDrawer extends StatefulWidget {
final AppUser signedInUser;
final ImageProvider<Object>? propicFile;
const MIHAppDrawer({
super.key,
required this.signedInUser,
required this.propicFile,
});
@override
@@ -35,19 +29,23 @@ class _MIHAppDrawerState extends State<MIHAppDrawer> {
return true;
}
Widget displayProPic() {
Widget displayProPic(MzansiProfileProvider mzansiProfileProvider) {
return GestureDetector(
onTap: () {
context.goNamed(
'mzansiProfileManage',
extra: AppProfileUpdateArguments(
widget.signedInUser,
widget.propicFile,
),
);
if (mzansiProfileProvider.personalHome) {
context.goNamed(
'mzansiProfileManage',
);
} else {
context.goNamed(
"businessProfileManage",
);
}
},
child: MihCircleAvatar(
imageFile: widget.propicFile,
imageFile: mzansiProfileProvider.personalHome
? mzansiProfileProvider.userProfilePicture
: mzansiProfileProvider.businessProfilePicture,
width: 60,
editable: false,
fileNameController: proPicController,
@@ -69,9 +67,6 @@ class _MIHAppDrawerState extends State<MIHAppDrawer> {
@override
void initState() {
setState(() {
profilePictureLoaded = displayProPic();
});
super.initState();
}
@@ -102,38 +97,74 @@ class _MIHAppDrawerState extends State<MIHAppDrawer> {
"Dark"),
),
child: SizedBox(
height: 400,
// height: 300,
width: constraints.maxWidth,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.max,
children: [
profilePictureLoaded,
Text(
"${widget.signedInUser.fname} ${widget.signedInUser.lname}",
style: TextStyle(
fontWeight: FontWeight.bold,
color: MihColors.getPrimaryColor(
MzansiInnovationHub.of(context)!
.theme
.mode ==
"Dark"),
displayProPic(mzansiProfileProvider),
Visibility(
visible: !mzansiProfileProvider.personalHome,
child: Text(
mzansiProfileProvider.business!.Name,
style: TextStyle(
fontWeight: FontWeight.bold,
color: MihColors.getPrimaryColor(
MzansiInnovationHub.of(context)!
.theme
.mode ==
"Dark"),
),
),
),
Visibility(
visible: mzansiProfileProvider.personalHome,
child: Text(
"${mzansiProfileProvider.user!.fname} ${mzansiProfileProvider.user!.lname}",
style: TextStyle(
fontWeight: FontWeight.bold,
color: MihColors.getPrimaryColor(
MzansiInnovationHub.of(context)!
.theme
.mode ==
"Dark"),
),
),
),
Visibility(
visible: !mzansiProfileProvider.personalHome,
child: Text(
mzansiProfileProvider.business!.type,
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.bold,
color: MihColors.getPrimaryColor(
MzansiInnovationHub.of(context)!
.theme
.mode ==
"Dark"),
),
),
),
Visibility(
visible: mzansiProfileProvider.personalHome,
child: Text(
"@${mzansiProfileProvider.user!.username}",
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.bold,
color: MihColors.getPrimaryColor(
MzansiInnovationHub.of(context)!
.theme
.mode ==
"Dark"),
),
),
),
Text(
"@${widget.signedInUser.username}",
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.bold,
color: MihColors.getPrimaryColor(
MzansiInnovationHub.of(context)!
.theme
.mode ==
"Dark"),
),
),
Text(
widget.signedInUser.type.toUpperCase(),
mzansiProfileProvider.user!.type
.toUpperCase(),
style: TextStyle(
fontSize: 10,
fontWeight: FontWeight.bold,

View File

@@ -39,8 +39,6 @@ class MihHome extends StatefulWidget {
}
class _MihHomeState extends State<MihHome> {
late int _selcetedIndex;
late bool _personalHome;
DateTime latestPrivacyPolicyDate = DateTime.parse("2024-12-01");
DateTime latestTermOfServiceDate = DateTime.parse("2024-12-01");
bool _isLoadingInitialData = true;
@@ -206,13 +204,6 @@ class _MihHomeState extends State<MihHome> {
@override
void initState() {
super.initState();
if (context.read<MzansiProfileProvider>().personalHome == true) {
_selcetedIndex = 0;
_personalHome = true;
} else {
_selcetedIndex = 1;
_personalHome = false;
}
_loadInitialData();
}
@@ -249,26 +240,16 @@ class _MihHomeState extends State<MihHome> {
child: SizedBox(
height: MediaQuery.of(context).size.height,
child: MihPackage(
appActionButton: getAction(
mzansiProfileProvider.userProfilePicUrl as String),
appTools: getTools(
appActionButton: getAction(),
appTools: getTools(mzansiProfileProvider,
mzansiProfileProvider.user!.type != "personal"),
appBody: getToolBody(),
appBody: getToolBody(mzansiProfileProvider),
appToolTitles: getToolTitle(),
actionDrawer: getActionDrawer(),
selectedbodyIndex: _selcetedIndex,
selectedbodyIndex:
mzansiProfileProvider.personalHome ? 0 : 1,
onIndexChange: (newValue) {
if (_selcetedIndex == 0) {
setState(() {
_selcetedIndex = newValue;
_personalHome = true;
});
} else {
setState(() {
_selcetedIndex = newValue;
_personalHome = false;
});
}
mzansiProfileProvider.setPersonalHome(newValue == 0);
},
),
),
@@ -474,81 +455,88 @@ class _MihHomeState extends State<MihHome> {
);
}
Widget getAction(String proPicUrl) {
Widget getAction() {
return Builder(builder: (context) {
return MihPackageAction(
icon: Padding(
padding: const EdgeInsets.only(left: 5.0),
child: MihCircleAvatar(
imageFile: proPicUrl != "" ? NetworkImage(proPicUrl) : null,
width: 50,
editable: false,
fileNameController: null,
userSelectedfile: null,
// frameColor: frameColor,
frameColor: MihColors.getSecondaryColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
backgroundColor: MihColors.getPrimaryColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
onChange: (_) {},
),
),
iconSize: 45,
onTap: () {
Scaffold.of(context).openDrawer();
FocusScope.of(context)
.requestFocus(FocusNode()); // Fully unfocus all fields
// FocusScope.of(context).unfocus(); // Unfocus any text fields
return Consumer<MzansiProfileProvider>(
builder: (BuildContext context,
MzansiProfileProvider mzansiProfileProvider, Widget? child) {
ImageProvider<Object>? currentImage;
String imageKey;
if (mzansiProfileProvider.personalHome) {
currentImage = mzansiProfileProvider.userProfilePicture;
imageKey = 'user_${mzansiProfileProvider.userProfilePicUrl}';
} else {
currentImage = mzansiProfileProvider.businessProfilePicture;
imageKey =
'business_${mzansiProfileProvider.businessProfilePicUrl}';
}
return MihPackageAction(
icon: Padding(
padding: const EdgeInsets.only(left: 5.0),
child: MihCircleAvatar(
key: Key(imageKey),
imageFile: currentImage,
width: 50,
editable: false,
fileNameController: null,
userSelectedfile: null,
// frameColor: frameColor,
frameColor: MihColors.getSecondaryColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
backgroundColor: MihColors.getPrimaryColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
onChange: (_) {},
),
),
iconSize: 45,
onTap: () {
Scaffold.of(context).openDrawer();
FocusScope.of(context)
.requestFocus(FocusNode()); // Fully unfocus all fields
// FocusScope.of(context).unfocus(); // Unfocus any text fields
},
);
},
);
});
}
MIHAppDrawer getActionDrawer() {
AppUser signedInUser =
context.watch<MzansiProfileProvider>().user as AppUser;
String proPicUrl =
context.watch<MzansiProfileProvider>().userProfilePicUrl ?? "";
return MIHAppDrawer(
signedInUser: signedInUser,
propicFile: proPicUrl != "" ? NetworkImage(proPicUrl) : null,
);
return MIHAppDrawer();
}
MihPackageTools getTools(bool isBusinessUser) {
MihPackageTools getTools(
MzansiProfileProvider mzansiProfileProvider, bool isBusinessUser) {
Map<Widget, void Function()?> temp = {};
temp[const Icon(Icons.person)] = () {
setState(() {
_selcetedIndex = 0;
_personalHome = true;
mzansiProfileProvider.setPersonalHome(true);
});
};
if (isBusinessUser) {
temp[const Icon(Icons.business_center)] = () {
setState(() {
_selcetedIndex = 1;
_personalHome = false;
mzansiProfileProvider.setPersonalHome(false);
});
};
}
return MihPackageTools(
tools: temp,
selcetedIndex: _selcetedIndex,
selcetedIndex: mzansiProfileProvider.personalHome ? 0 : 1,
);
}
List<Widget> getToolBody() {
List<Widget> getToolBody(MzansiProfileProvider mzansiProfileProvider) {
List<Widget> toolBodies = [];
AppUser? user = context.watch<MzansiProfileProvider>().user;
Business? business = context.watch<MzansiProfileProvider>().business;
BusinessUser? businessUser =
context.watch<MzansiProfileProvider>().businessUser;
AppUser? user = mzansiProfileProvider.user;
Business? business = mzansiProfileProvider.business;
BusinessUser? businessUser = mzansiProfileProvider.businessUser;
String userProfilePictureUrl =
context.watch<MzansiProfileProvider>().userProfilePicUrl ?? "";
mzansiProfileProvider.userProfilePicUrl ?? "";
toolBodies.add(
MihPersonalHome(
signedInUser: user!,
personalSelected: _personalHome,
personalSelected: mzansiProfileProvider.personalHome,
business: business,
businessUser: businessUser,
propicFile: userProfilePictureUrl != ""

View File

@@ -31,7 +31,6 @@ class _MzansiAiState extends State<MzansiAi> {
onTap: () {
context.goNamed(
'mihHome',
extra: widget.arguments.personalSelected,
);
FocusScope.of(context).unfocus();
},

View File

@@ -100,7 +100,6 @@ class _MzansiDirectoryState extends State<MzansiDirectory> {
onTap: () {
context.goNamed(
'mihHome',
extra: widget.arguments.personalSearch,
);
FocusScope.of(context).unfocus();
},

View File

@@ -43,7 +43,6 @@ class _MzansiBusinessProfileState extends State<MzansiBusinessProfile> {
onTap: () {
context.goNamed(
'mihHome',
extra: false,
);
FocusScope.of(context).unfocus();
context.read<MzansiProfileProvider>().setBusinessIndex(0);

View File

@@ -40,7 +40,6 @@ class _MzansiProfileState extends State<MzansiProfile> {
// Navigator.of(context).pop();
context.goNamed(
'mihHome',
extra: true,
);
FocusScope.of(context).unfocus();
},

View File

@@ -81,7 +81,6 @@ class _MihWalletState extends State<MihWallet> {
onTap: () {
context.goNamed(
'mihHome',
extra: true,
);
FocusScope.of(context).unfocus();
},

View File

@@ -52,7 +52,6 @@ class _PatManagerState extends State<PatManager> {
// Navigator.of(context).pop();
context.goNamed(
'mihHome',
extra: false,
);
FocusScope.of(context).unfocus();
},

View File

@@ -48,7 +48,6 @@ class _PatientProfileState extends State<PatientProfile> {
} else {
context.goNamed(
'mihHome',
extra: true,
);
}
FocusScope.of(context).unfocus();