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> {
|
class _MzansiBusinessProfileViewState extends State<MzansiBusinessProfileView> {
|
||||||
int _selectedIndex = 0;
|
|
||||||
late final MihBusinessDetailsView _businessDetailsView;
|
late final MihBusinessDetailsView _businessDetailsView;
|
||||||
late final MihBusinessReviews _businessReviews;
|
late final MihBusinessReviews _businessReviews;
|
||||||
late final MihBusinessQrCode _businessQrCode;
|
late final MihBusinessQrCode _businessQrCode;
|
||||||
@@ -57,6 +56,7 @@ class _MzansiBusinessProfileViewState extends State<MzansiBusinessProfileView> {
|
|||||||
super.initState();
|
super.initState();
|
||||||
MzansiDirectoryProvider directoryProvider =
|
MzansiDirectoryProvider directoryProvider =
|
||||||
context.read<MzansiDirectoryProvider>();
|
context.read<MzansiDirectoryProvider>();
|
||||||
|
directoryProvider.setBusinessViewIndex(0);
|
||||||
_fetchBusinessDetails(directoryProvider);
|
_fetchBusinessDetails(directoryProvider);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,11 +78,9 @@ class _MzansiBusinessProfileViewState extends State<MzansiBusinessProfileView> {
|
|||||||
packageTools: getTools(),
|
packageTools: getTools(),
|
||||||
packageToolBodies: getToolBody(directoryProvider),
|
packageToolBodies: getToolBody(directoryProvider),
|
||||||
packageToolTitles: getToolTitle(),
|
packageToolTitles: getToolTitle(),
|
||||||
selectedBodyIndex: _selectedIndex,
|
selectedBodyIndex: directoryProvider.businessViewIndex,
|
||||||
onIndexChange: (newValue) {
|
onIndexChange: (newValue) {
|
||||||
setState(() {
|
directoryProvider.setBusinessViewIndex(newValue);
|
||||||
_selectedIndex = newValue;
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -114,23 +112,17 @@ class _MzansiBusinessProfileViewState extends State<MzansiBusinessProfileView> {
|
|||||||
MihPackageTools getTools() {
|
MihPackageTools getTools() {
|
||||||
Map<Widget, void Function()?> temp = {};
|
Map<Widget, void Function()?> temp = {};
|
||||||
temp[const Icon(Icons.business)] = () {
|
temp[const Icon(Icons.business)] = () {
|
||||||
setState(() {
|
context.read<MzansiDirectoryProvider>().setBusinessViewIndex(0);
|
||||||
_selectedIndex = 0;
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
temp[const Icon(Icons.star_rate_rounded)] = () {
|
temp[const Icon(Icons.star_rate_rounded)] = () {
|
||||||
setState(() {
|
context.read<MzansiDirectoryProvider>().setBusinessViewIndex(1);
|
||||||
_selectedIndex = 1;
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
temp[const Icon(Icons.qr_code_rounded)] = () {
|
temp[const Icon(Icons.qr_code_rounded)] = () {
|
||||||
setState(() {
|
context.read<MzansiDirectoryProvider>().setBusinessViewIndex(2);
|
||||||
_selectedIndex = 2;
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
return MihPackageTools(
|
return MihPackageTools(
|
||||||
tools: temp,
|
tools: temp,
|
||||||
selectedIndex: _selectedIndex,
|
selectedIndex: context.watch<MzansiDirectoryProvider>().businessViewIndex,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,13 +20,13 @@ class MzansiProfileView extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _MzansiProfileViewState extends State<MzansiProfileView> {
|
class _MzansiProfileViewState extends State<MzansiProfileView> {
|
||||||
int _selectedIndex = 0;
|
|
||||||
late final MihPersonalProfileView _personalProfileView;
|
late final MihPersonalProfileView _personalProfileView;
|
||||||
late final MihPersonalQrCode _personalQrCode;
|
late final MihPersonalQrCode _personalQrCode;
|
||||||
|
|
||||||
void _loadUserData() async {
|
void _loadUserData() async {
|
||||||
MzansiDirectoryProvider directoryProvider =
|
MzansiDirectoryProvider directoryProvider =
|
||||||
context.read<MzansiDirectoryProvider>();
|
context.read<MzansiDirectoryProvider>();
|
||||||
|
directoryProvider.setPersonalViewIndex(0);
|
||||||
if (widget.username != null) {
|
if (widget.username != null) {
|
||||||
final user = await MihUserServices()
|
final user = await MihUserServices()
|
||||||
.getMIHUserDetailsByUsername(widget.username!, context);
|
.getMIHUserDetailsByUsername(widget.username!, context);
|
||||||
@@ -68,11 +68,9 @@ class _MzansiProfileViewState extends State<MzansiProfileView> {
|
|||||||
packageTools: getTools(),
|
packageTools: getTools(),
|
||||||
packageToolBodies: getToolBody(),
|
packageToolBodies: getToolBody(),
|
||||||
packageToolTitles: getToolTitle(),
|
packageToolTitles: getToolTitle(),
|
||||||
selectedBodyIndex: _selectedIndex,
|
selectedBodyIndex: directoryProvider.personalViewIndex,
|
||||||
onIndexChange: (newValue) {
|
onIndexChange: (newValue) {
|
||||||
setState(() {
|
directoryProvider.setPersonalViewIndex(newValue);
|
||||||
_selectedIndex = newValue;
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -95,18 +93,14 @@ class _MzansiProfileViewState extends State<MzansiProfileView> {
|
|||||||
MihPackageTools getTools() {
|
MihPackageTools getTools() {
|
||||||
Map<Widget, void Function()?> temp = {};
|
Map<Widget, void Function()?> temp = {};
|
||||||
temp[const Icon(Icons.person)] = () {
|
temp[const Icon(Icons.person)] = () {
|
||||||
setState(() {
|
context.read<MzansiDirectoryProvider>().setPersonalViewIndex(0);
|
||||||
_selectedIndex = 0;
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
temp[const Icon(Icons.qr_code_rounded)] = () {
|
temp[const Icon(Icons.qr_code_rounded)] = () {
|
||||||
setState(() {
|
context.read<MzansiDirectoryProvider>().setPersonalViewIndex(1);
|
||||||
_selectedIndex = 1;
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
return MihPackageTools(
|
return MihPackageTools(
|
||||||
tools: temp,
|
tools: temp,
|
||||||
selectedIndex: _selectedIndex,
|
selectedIndex: context.watch<MzansiDirectoryProvider>().personalViewIndex,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+3
-2
@@ -56,7 +56,8 @@ class _MihPersonalQrCodeState extends State<MihPersonalQrCode> {
|
|||||||
String bgColor =
|
String bgColor =
|
||||||
MihColors.secondary().toARGB32().toRadixString(16).substring(2, 8);
|
MihColors.secondary().toARGB32().toRadixString(16).substring(2, 8);
|
||||||
// KenLogger.warning(bgColor);
|
// 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";
|
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(
|
shareMIHLink(
|
||||||
context,
|
context,
|
||||||
"Check out ${user.username} on the MIH app's Mzansi Directory",
|
"Check out ${user.username} on the MIH app's Mzansi Directory",
|
||||||
"$_qrCodedata${user.username}",
|
"$_qrCodedata${user.username.toLowerCase()}",
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -3,10 +3,11 @@ import 'package:geolocator/geolocator.dart';
|
|||||||
import 'package:mzansi_innovation_hub/mih_objects/app_user.dart';
|
import 'package:mzansi_innovation_hub/mih_objects/app_user.dart';
|
||||||
import 'package:mzansi_innovation_hub/mih_objects/bookmarked_business.dart';
|
import 'package:mzansi_innovation_hub/mih_objects/bookmarked_business.dart';
|
||||||
import 'package:mzansi_innovation_hub/mih_objects/business.dart';
|
import 'package:mzansi_innovation_hub/mih_objects/business.dart';
|
||||||
import 'package:mzansi_innovation_hub/mih_objects/profile_link.dart';
|
|
||||||
|
|
||||||
class MzansiDirectoryProvider extends ChangeNotifier {
|
class MzansiDirectoryProvider extends ChangeNotifier {
|
||||||
int toolIndex;
|
int toolIndex;
|
||||||
|
int personalViewIndex;
|
||||||
|
int businessViewIndex;
|
||||||
Position? userPosition;
|
Position? userPosition;
|
||||||
String userLocation;
|
String userLocation;
|
||||||
bool personalSearch;
|
bool personalSearch;
|
||||||
@@ -24,6 +25,8 @@ class MzansiDirectoryProvider extends ChangeNotifier {
|
|||||||
|
|
||||||
MzansiDirectoryProvider({
|
MzansiDirectoryProvider({
|
||||||
this.toolIndex = 0,
|
this.toolIndex = 0,
|
||||||
|
this.personalViewIndex = 0,
|
||||||
|
this.businessViewIndex = 0,
|
||||||
this.personalSearch = true,
|
this.personalSearch = true,
|
||||||
this.userLocation = "Unknown Location",
|
this.userLocation = "Unknown Location",
|
||||||
this.searchTerm = "",
|
this.searchTerm = "",
|
||||||
@@ -32,6 +35,8 @@ class MzansiDirectoryProvider extends ChangeNotifier {
|
|||||||
|
|
||||||
void reset() {
|
void reset() {
|
||||||
toolIndex = 0;
|
toolIndex = 0;
|
||||||
|
personalViewIndex = 0;
|
||||||
|
businessViewIndex = 0;
|
||||||
userPosition = null;
|
userPosition = null;
|
||||||
userLocation = "Unknown Location";
|
userLocation = "Unknown Location";
|
||||||
personalSearch = true;
|
personalSearch = true;
|
||||||
@@ -50,6 +55,16 @@ class MzansiDirectoryProvider extends ChangeNotifier {
|
|||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setPersonalViewIndex(int index) {
|
||||||
|
personalViewIndex = index;
|
||||||
|
notifyListeners();
|
||||||
|
}
|
||||||
|
|
||||||
|
void setBusinessViewIndex(int index) {
|
||||||
|
businessViewIndex = index;
|
||||||
|
notifyListeners();
|
||||||
|
}
|
||||||
|
|
||||||
void setUserPosition(Position? position) {
|
void setUserPosition(Position? position) {
|
||||||
userPosition = position;
|
userPosition = position;
|
||||||
if (position == null) {
|
if (position == null) {
|
||||||
|
|||||||
Reference in New Issue
Block a user