add provider indexing for business & user views
This commit is contained in:
+7
-15
@@ -24,7 +24,6 @@ class MzansiBusinessProfileView extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _MzansiBusinessProfileViewState extends State<MzansiBusinessProfileView> {
|
||||
int _selectedIndex = 0;
|
||||
late final MihBusinessDetailsView _businessDetailsView;
|
||||
late final MihBusinessReviews _businessReviews;
|
||||
late final MihBusinessQrCode _businessQrCode;
|
||||
@@ -57,6 +56,7 @@ class _MzansiBusinessProfileViewState extends State<MzansiBusinessProfileView> {
|
||||
super.initState();
|
||||
MzansiDirectoryProvider directoryProvider =
|
||||
context.read<MzansiDirectoryProvider>();
|
||||
directoryProvider.setBusinessViewIndex(0);
|
||||
_fetchBusinessDetails(directoryProvider);
|
||||
}
|
||||
|
||||
@@ -78,11 +78,9 @@ class _MzansiBusinessProfileViewState extends State<MzansiBusinessProfileView> {
|
||||
packageTools: getTools(),
|
||||
packageToolBodies: getToolBody(directoryProvider),
|
||||
packageToolTitles: getToolTitle(),
|
||||
selectedBodyIndex: _selectedIndex,
|
||||
selectedBodyIndex: directoryProvider.businessViewIndex,
|
||||
onIndexChange: (newValue) {
|
||||
setState(() {
|
||||
_selectedIndex = newValue;
|
||||
});
|
||||
directoryProvider.setBusinessViewIndex(newValue);
|
||||
},
|
||||
);
|
||||
}
|
||||
@@ -114,23 +112,17 @@ class _MzansiBusinessProfileViewState extends State<MzansiBusinessProfileView> {
|
||||
MihPackageTools getTools() {
|
||||
Map<Widget, void Function()?> temp = {};
|
||||
temp[const Icon(Icons.business)] = () {
|
||||
setState(() {
|
||||
_selectedIndex = 0;
|
||||
});
|
||||
context.read<MzansiDirectoryProvider>().setBusinessViewIndex(0);
|
||||
};
|
||||
temp[const Icon(Icons.star_rate_rounded)] = () {
|
||||
setState(() {
|
||||
_selectedIndex = 1;
|
||||
});
|
||||
context.read<MzansiDirectoryProvider>().setBusinessViewIndex(1);
|
||||
};
|
||||
temp[const Icon(Icons.qr_code_rounded)] = () {
|
||||
setState(() {
|
||||
_selectedIndex = 2;
|
||||
});
|
||||
context.read<MzansiDirectoryProvider>().setBusinessViewIndex(2);
|
||||
};
|
||||
return MihPackageTools(
|
||||
tools: temp,
|
||||
selectedIndex: _selectedIndex,
|
||||
selectedIndex: context.watch<MzansiDirectoryProvider>().businessViewIndex,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -20,13 +20,13 @@ class MzansiProfileView extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _MzansiProfileViewState extends State<MzansiProfileView> {
|
||||
int _selectedIndex = 0;
|
||||
late final MihPersonalProfileView _personalProfileView;
|
||||
late final MihPersonalQrCode _personalQrCode;
|
||||
|
||||
void _loadUserData() async {
|
||||
MzansiDirectoryProvider directoryProvider =
|
||||
context.read<MzansiDirectoryProvider>();
|
||||
directoryProvider.setPersonalViewIndex(0);
|
||||
if (widget.username != null) {
|
||||
final user = await MihUserServices()
|
||||
.getMIHUserDetailsByUsername(widget.username!, context);
|
||||
@@ -68,11 +68,9 @@ class _MzansiProfileViewState extends State<MzansiProfileView> {
|
||||
packageTools: getTools(),
|
||||
packageToolBodies: getToolBody(),
|
||||
packageToolTitles: getToolTitle(),
|
||||
selectedBodyIndex: _selectedIndex,
|
||||
selectedBodyIndex: directoryProvider.personalViewIndex,
|
||||
onIndexChange: (newValue) {
|
||||
setState(() {
|
||||
_selectedIndex = newValue;
|
||||
});
|
||||
directoryProvider.setPersonalViewIndex(newValue);
|
||||
},
|
||||
);
|
||||
}
|
||||
@@ -95,18 +93,14 @@ class _MzansiProfileViewState extends State<MzansiProfileView> {
|
||||
MihPackageTools getTools() {
|
||||
Map<Widget, void Function()?> temp = {};
|
||||
temp[const Icon(Icons.person)] = () {
|
||||
setState(() {
|
||||
_selectedIndex = 0;
|
||||
});
|
||||
context.read<MzansiDirectoryProvider>().setPersonalViewIndex(0);
|
||||
};
|
||||
temp[const Icon(Icons.qr_code_rounded)] = () {
|
||||
setState(() {
|
||||
_selectedIndex = 1;
|
||||
});
|
||||
context.read<MzansiDirectoryProvider>().setPersonalViewIndex(1);
|
||||
};
|
||||
return MihPackageTools(
|
||||
tools: temp,
|
||||
selectedIndex: _selectedIndex,
|
||||
selectedIndex: context.watch<MzansiDirectoryProvider>().personalViewIndex,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
+3
-2
@@ -56,7 +56,8 @@ class _MihPersonalQrCodeState extends State<MihPersonalQrCode> {
|
||||
String bgColor =
|
||||
MihColors.secondary().toARGB32().toRadixString(16).substring(2, 8);
|
||||
// KenLogger.warning(bgColor);
|
||||
String encodedData = Uri.encodeComponent("$_qrCodedata${user.username}");
|
||||
String encodedData =
|
||||
Uri.encodeComponent("$_qrCodedata${user.username.toLowerCase()}");
|
||||
return "https://api.qrserver.com/v1/create-qr-code/?data=$encodedData&size=${qrSize}x$qrSize&bgcolor=$bgColor&color=$color";
|
||||
}
|
||||
|
||||
@@ -398,7 +399,7 @@ class _MihPersonalQrCodeState extends State<MihPersonalQrCode> {
|
||||
shareMIHLink(
|
||||
context,
|
||||
"Check out ${user.username} on the MIH app's Mzansi Directory",
|
||||
"$_qrCodedata${user.username}",
|
||||
"$_qrCodedata${user.username.toLowerCase()}",
|
||||
);
|
||||
},
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user