NEW: fix home nav
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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 != ""
|
||||
|
||||
Reference in New Issue
Block a user