QOL: Data display load Mzansi Direct pt4
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:geolocator/geolocator.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_objects/business.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_package_components/mih_package.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_package_components/mih_package_action.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_package_components/mih_package_tools.dart';
|
||||
@@ -10,11 +9,8 @@ import 'package:mzansi_innovation_hub/mih_providers/mzansi_directory_provider.da
|
||||
import 'package:mzansi_innovation_hub/mih_providers/mzansi_profile_provider.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_packages/mzansi_directory/package_tools/mih_favourite_businesses.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_packages/mzansi_directory/package_tools/mih_search_mzansi.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_services/mih_business_details_services.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_services/mih_data_helper_services.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_services/mih_file_services.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_services/mih_location_services.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_services/mih_mzansi_directory_services.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class MzansiDirectory extends StatefulWidget {
|
||||
@@ -42,7 +38,6 @@ class _MzansiDirectoryState extends State<MzansiDirectory> {
|
||||
await MihDataHelperServices().loadUserDataOnly(
|
||||
mzansiProfileProvider,
|
||||
);
|
||||
// await getFavouriteBusinesses();
|
||||
setState(() {
|
||||
_isLoadingInitialData = false;
|
||||
});
|
||||
@@ -56,86 +51,6 @@ class _MzansiDirectoryState extends State<MzansiDirectory> {
|
||||
directoryProvider.setUserPosition(userPos);
|
||||
}
|
||||
|
||||
Future<void> getFavouriteBusinesses() async {
|
||||
MzansiDirectoryProvider directoryProvider =
|
||||
context.read<MzansiDirectoryProvider>();
|
||||
MzansiProfileProvider profileProvider =
|
||||
context.read<MzansiProfileProvider>();
|
||||
await MihMzansiDirectoryServices().getAllUserBookmarkedBusiness(
|
||||
profileProvider.user!.app_id,
|
||||
directoryProvider,
|
||||
);
|
||||
List<Business> favBus = [];
|
||||
// Map<String, ImageProvider<Object>?> favBusImages = {};
|
||||
Map<String, Future<String>> favBusImages = {};
|
||||
// String businessLogoUrl = "";
|
||||
Future<String> businessLogoUrl;
|
||||
for (var bus in directoryProvider.bookmarkedBusinesses) {
|
||||
await MihBusinessDetailsServices()
|
||||
.getBusinessDetailsByBusinessId(bus.business_id)
|
||||
.then((business) async {
|
||||
favBus.add(business!);
|
||||
businessLogoUrl = MihFileApi.getMinioFileUrl(business.logo_path);
|
||||
favBusImages[business.business_id] = businessLogoUrl;
|
||||
// != ""
|
||||
// ? CachedNetworkImageProvider(businessLogoUrl)
|
||||
// : null;
|
||||
});
|
||||
}
|
||||
directoryProvider.setFavouriteBusinesses(
|
||||
businesses: favBus,
|
||||
businessesImagesUrl: favBusImages,
|
||||
);
|
||||
}
|
||||
// // --- REVISED FUNCTION FOR PARALLEL FETCHING ---
|
||||
// Future<void> getFavouriteBusinesses() async {
|
||||
// MzansiDirectoryProvider directoryProvider =
|
||||
// context.read<MzansiDirectoryProvider>();
|
||||
// MzansiProfileProvider profileProvider =
|
||||
// context.read<MzansiProfileProvider>();
|
||||
// // 1. Fetch the list of bookmarked business IDs
|
||||
// await MihMzansiDirectoryServices().getAllUserBookmarkedBusiness(
|
||||
// profileProvider.user!.app_id,
|
||||
// directoryProvider,
|
||||
// );
|
||||
// // 2. Map bookmarked businesses to a list of Futures
|
||||
// // Each Future will fetch the business details AND the logo URL concurrently
|
||||
// final List<Future<(Business?, String?)>> detailAndUrlFutures =
|
||||
// directoryProvider.bookmarkedBusinesses.map((bookmarkedBus) {
|
||||
// return MihBusinessDetailsServices()
|
||||
// .getBusinessDetailsByBusinessId(bookmarkedBus.business_id)
|
||||
// .then((business) async {
|
||||
// if (business == null) return (null, null);
|
||||
// // Fetch logo URL for this business concurrently
|
||||
// String businessLogoUrl =
|
||||
// await MihFileApi.getMinioFileUrl(business.logo_path);
|
||||
// return (business, businessLogoUrl);
|
||||
// });
|
||||
// }).toList();
|
||||
// // 3. Wait for ALL futures to complete in parallel
|
||||
// List<(Business?, String?)> results = await Future.wait(detailAndUrlFutures);
|
||||
// // 4. Process the results
|
||||
// List<Business> favBus = [];
|
||||
// Map<String, ImageProvider<Object>?> favBusImages = {};
|
||||
// for (var result in results) {
|
||||
// final business = result.$1;
|
||||
// final businessLogoUrl = result.$2;
|
||||
// if (business != null) {
|
||||
// favBus.add(business);
|
||||
// favBusImages[business.business_id] =
|
||||
// (businessLogoUrl != null && businessLogoUrl.isNotEmpty)
|
||||
// ? NetworkImage(businessLogoUrl)
|
||||
// : null;
|
||||
// }
|
||||
// }
|
||||
// // 5. Update the provider once with all the data
|
||||
// directoryProvider.setFavouriteBusinesses(
|
||||
// businesses: favBus,
|
||||
// businessesImages: favBusImages,
|
||||
// );
|
||||
// }
|
||||
|
||||
// // ---------------------------------------------
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
@@ -41,26 +41,26 @@ class _MihFavouriteBusinessesState extends State<MihFavouriteBusinesses> {
|
||||
profileProvider.user!.app_id,
|
||||
directoryProvider,
|
||||
);
|
||||
List<Business> favBus = [];
|
||||
// Map<String, ImageProvider<Object>?> favBusImages = {};
|
||||
Map<String, Future<String>> favBusImages = {};
|
||||
// String businessLogoUrl = "";
|
||||
Future<String> businessLogoUrl;
|
||||
for (var bus in directoryProvider.bookmarkedBusinesses) {
|
||||
await MihBusinessDetailsServices()
|
||||
.getBusinessDetailsByBusinessId(bus.business_id)
|
||||
.then((business) async {
|
||||
favBus.add(business!);
|
||||
businessLogoUrl = MihFileApi.getMinioFileUrl(business.logo_path);
|
||||
favBusImages[business.business_id] = businessLogoUrl;
|
||||
// businessLogoUrl != "" ? NetworkImage(businessLogoUrl) : null;
|
||||
});
|
||||
}
|
||||
directoryProvider.setFavouriteBusinesses(
|
||||
businesses: favBus,
|
||||
businessesImagesUrl: favBusImages,
|
||||
);
|
||||
}
|
||||
List<Business> favBus = [];
|
||||
// Map<String, ImageProvider<Object>?> favBusImages = {};
|
||||
Map<String, Future<String>> favBusImages = {};
|
||||
// String businessLogoUrl = "";
|
||||
Future<String> businessLogoUrl;
|
||||
for (var bus in directoryProvider.bookmarkedBusinesses) {
|
||||
await MihBusinessDetailsServices()
|
||||
.getBusinessDetailsByBusinessId(bus.business_id)
|
||||
.then((business) async {
|
||||
favBus.add(business!);
|
||||
businessLogoUrl = MihFileApi.getMinioFileUrl(business.logo_path);
|
||||
favBusImages[business.business_id] = businessLogoUrl;
|
||||
// businessLogoUrl != "" ? NetworkImage(businessLogoUrl) : null;
|
||||
});
|
||||
}
|
||||
directoryProvider.setFavouriteBusinesses(
|
||||
businesses: favBus,
|
||||
businessesImagesUrl: favBusImages,
|
||||
);
|
||||
}
|
||||
|
||||
void _filterAndSetBusinesses(MzansiDirectoryProvider directoryProvider) {
|
||||
|
||||
@@ -125,19 +125,21 @@ class _MihAddBookmarkAlertState extends State<MihAddBookmarkAlert> {
|
||||
fullscreen: false,
|
||||
windowTitle: null,
|
||||
onWindowTapClose: null,
|
||||
backgroundColor: MihColors.getSecondaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
|
||||
windowBody: Column(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.warning_rounded,
|
||||
size: 150,
|
||||
color: MihColors.getSecondaryColor(
|
||||
color: MihColors.getPrimaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
|
||||
),
|
||||
Text(
|
||||
"Bookmark Business",
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
color: MihColors.getSecondaryColor(
|
||||
color: MihColors.getPrimaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
|
||||
fontSize: 25,
|
||||
fontWeight: FontWeight.bold,
|
||||
@@ -147,7 +149,7 @@ class _MihAddBookmarkAlertState extends State<MihAddBookmarkAlert> {
|
||||
Text(
|
||||
"Are you sure you want to save ${widget.business.Name} to your Mzansi Directory?",
|
||||
style: TextStyle(
|
||||
color: MihColors.getSecondaryColor(
|
||||
color: MihColors.getPrimaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
|
||||
fontSize: 18,
|
||||
),
|
||||
|
||||
@@ -126,19 +126,21 @@ class _MihDeleteBookmarkAlertState extends State<MihDeleteBookmarkAlert> {
|
||||
fullscreen: false,
|
||||
windowTitle: null,
|
||||
onWindowTapClose: null,
|
||||
backgroundColor: MihColors.getSecondaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
|
||||
windowBody: Column(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.warning_rounded,
|
||||
size: 150,
|
||||
color: MihColors.getSecondaryColor(
|
||||
color: MihColors.getPrimaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
|
||||
),
|
||||
Text(
|
||||
"Remove Bookmark",
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
color: MihColors.getSecondaryColor(
|
||||
color: MihColors.getPrimaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
|
||||
fontSize: 25,
|
||||
fontWeight: FontWeight.bold,
|
||||
@@ -148,7 +150,7 @@ class _MihDeleteBookmarkAlertState extends State<MihDeleteBookmarkAlert> {
|
||||
Text(
|
||||
"Are you sure you want to remove ${widget.business.Name} from your Mzansi Directory?",
|
||||
style: TextStyle(
|
||||
color: MihColors.getSecondaryColor(
|
||||
color: MihColors.getPrimaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
|
||||
fontSize: 18,
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user