QOL: Data display load Mzansi Direct pt1
This commit is contained in:
@@ -11,10 +11,12 @@ import 'package:provider/provider.dart';
|
||||
class MihBusinessProfilePreview extends StatefulWidget {
|
||||
final Business business;
|
||||
final ImageProvider<Object>? imageFile;
|
||||
final bool loading;
|
||||
const MihBusinessProfilePreview({
|
||||
super.key,
|
||||
required this.business,
|
||||
required this.imageFile,
|
||||
required this.loading,
|
||||
});
|
||||
|
||||
@override
|
||||
@@ -48,23 +50,35 @@ class _MihBusinessProfilePreviewState extends State<MihBusinessProfilePreview> {
|
||||
Widget? child) {
|
||||
return Row(
|
||||
children: [
|
||||
widget.imageFile == null
|
||||
widget.loading
|
||||
? Icon(
|
||||
MihIcons.iDontKnow,
|
||||
MihIcons.mihRing,
|
||||
size: profilePictureWidth,
|
||||
color: MihColors.getSecondaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
|
||||
)
|
||||
: MihCircleAvatar(
|
||||
imageFile: widget.imageFile,
|
||||
width: profilePictureWidth,
|
||||
editable: false,
|
||||
fileNameController: TextEditingController(),
|
||||
userSelectedfile: null,
|
||||
frameColor: MihColors.getSecondaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
|
||||
backgroundColor: MihColors.getPrimaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
|
||||
onChange: () {},
|
||||
),
|
||||
: widget.imageFile == null
|
||||
? Icon(
|
||||
MihIcons.iDontKnow,
|
||||
size: profilePictureWidth,
|
||||
color: MihColors.getSecondaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode ==
|
||||
"Dark"),
|
||||
)
|
||||
: MihCircleAvatar(
|
||||
imageFile: widget.imageFile,
|
||||
width: profilePictureWidth,
|
||||
editable: false,
|
||||
fileNameController: TextEditingController(),
|
||||
userSelectedfile: null,
|
||||
frameColor: MihColors.getSecondaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode ==
|
||||
"Dark"),
|
||||
backgroundColor: MihColors.getPrimaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode ==
|
||||
"Dark"),
|
||||
onChange: () {},
|
||||
),
|
||||
const SizedBox(width: 15),
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
|
||||
@@ -62,6 +62,8 @@ class _BuildBusinessSearchResultsListState
|
||||
business: widget.businessList[index],
|
||||
imageFile: directoryProvider.busSearchImages![
|
||||
widget.businessList[index].business_id],
|
||||
loading: false,
|
||||
//To Do
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import 'package:cached_network_image/cached_network_image.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:mzansi_innovation_hub/main.dart';
|
||||
@@ -21,6 +22,11 @@ class BuildFavouriteBusinessesList extends StatefulWidget {
|
||||
|
||||
class _BuildFavouriteBusinessesListState
|
||||
extends State<BuildFavouriteBusinessesList> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Consumer<MzansiDirectoryProvider>(
|
||||
@@ -57,11 +63,32 @@ class _BuildFavouriteBusinessesListState
|
||||
padding: EdgeInsets.symmetric(
|
||||
horizontal: 25,
|
||||
),
|
||||
child: MihBusinessProfilePreview(
|
||||
business: widget.favouriteBusinesses[index]!,
|
||||
imageFile: directoryProvider.favBusImages![
|
||||
widget.favouriteBusinesses[index]!.business_id],
|
||||
),
|
||||
child: FutureBuilder(
|
||||
future: directoryProvider.favBusImagesUrl![
|
||||
widget.favouriteBusinesses[index]!.business_id],
|
||||
builder: (context, asyncSnapshot) {
|
||||
ImageProvider<Object>? imageFile;
|
||||
bool loading = true;
|
||||
if (asyncSnapshot.connectionState ==
|
||||
ConnectionState.done) {
|
||||
loading = false;
|
||||
if (asyncSnapshot.hasData) {
|
||||
imageFile = asyncSnapshot.requireData != ""
|
||||
? CachedNetworkImageProvider(
|
||||
asyncSnapshot.requireData)
|
||||
: null;
|
||||
} else {
|
||||
imageFile = null;
|
||||
}
|
||||
} else {
|
||||
imageFile = null;
|
||||
}
|
||||
return MihBusinessProfilePreview(
|
||||
business: widget.favouriteBusinesses[index]!,
|
||||
imageFile: imageFile,
|
||||
loading: loading,
|
||||
);
|
||||
}),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import 'package:cached_network_image/cached_network_image.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:geolocator/geolocator.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
@@ -43,7 +42,7 @@ class _MzansiDirectoryState extends State<MzansiDirectory> {
|
||||
await MihDataHelperServices().loadUserDataOnly(
|
||||
mzansiProfileProvider,
|
||||
);
|
||||
await getFavouriteBusinesses();
|
||||
// await getFavouriteBusinesses();
|
||||
setState(() {
|
||||
_isLoadingInitialData = false;
|
||||
});
|
||||
@@ -67,22 +66,25 @@ class _MzansiDirectoryState extends State<MzansiDirectory> {
|
||||
directoryProvider,
|
||||
);
|
||||
List<Business> favBus = [];
|
||||
Map<String, ImageProvider<Object>?> favBusImages = {};
|
||||
String businessLogoUrl = "";
|
||||
// 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 = await MihFileApi.getMinioFileUrl(business.logo_path);
|
||||
favBusImages[business.business_id] = businessLogoUrl != ""
|
||||
? CachedNetworkImageProvider(businessLogoUrl)
|
||||
: null;
|
||||
businessLogoUrl = MihFileApi.getMinioFileUrl(business.logo_path);
|
||||
favBusImages[business.business_id] = businessLogoUrl;
|
||||
// != ""
|
||||
// ? CachedNetworkImageProvider(businessLogoUrl)
|
||||
// : null;
|
||||
});
|
||||
}
|
||||
directoryProvider.setFavouriteBusinesses(
|
||||
businesses: favBus,
|
||||
businessesImages: favBusImages,
|
||||
businessesImagesUrl: favBusImages,
|
||||
);
|
||||
}
|
||||
// // --- REVISED FUNCTION FOR PARALLEL FETCHING ---
|
||||
|
||||
@@ -9,6 +9,10 @@ import 'package:mzansi_innovation_hub/mih_package_components/mih_loading_circle.
|
||||
import 'package:mzansi_innovation_hub/mih_providers/mzansi_directory_provider.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_config/mih_colors.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_packages/mzansi_directory/builders/build_favourite_businesses_list.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_providers/mzansi_profile_provider.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_services/mih_business_details_services.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_services/mih_file_services.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_services/mih_mzansi_directory_services.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class MihFavouriteBusinesses extends StatefulWidget {
|
||||
@@ -28,6 +32,37 @@ class _MihFavouriteBusinessesState extends State<MihFavouriteBusinesses> {
|
||||
ValueNotifier([]);
|
||||
Timer? _debounce;
|
||||
|
||||
Future<void> getFavouriteBusinesses(
|
||||
MzansiDirectoryProvider directoryProvider) async {
|
||||
MzansiProfileProvider profileProvider =
|
||||
context.read<MzansiProfileProvider>();
|
||||
if (directoryProvider.bookmarkedBusinesses.isEmpty) {
|
||||
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;
|
||||
// businessLogoUrl != "" ? NetworkImage(businessLogoUrl) : null;
|
||||
});
|
||||
}
|
||||
directoryProvider.setFavouriteBusinesses(
|
||||
businesses: favBus,
|
||||
businessesImagesUrl: favBusImages,
|
||||
);
|
||||
}
|
||||
|
||||
void _filterAndSetBusinesses(MzansiDirectoryProvider directoryProvider) {
|
||||
List<Business?> businessesToDisplay = [];
|
||||
String query = businessSearchController.text.toLowerCase();
|
||||
@@ -58,6 +93,7 @@ class _MihFavouriteBusinessesState extends State<MihFavouriteBusinesses> {
|
||||
// mzansiProfileProvider,
|
||||
// directoryProvider,
|
||||
// );
|
||||
getFavouriteBusinesses(directoryProvider);
|
||||
_filterAndSetBusinesses(directoryProvider);
|
||||
businessSearchController.addListener(() {
|
||||
if (_debounce?.isActive ?? false) {
|
||||
@@ -141,7 +177,7 @@ class _MihFavouriteBusinessesState extends State<MihFavouriteBusinesses> {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10.0),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
const SizedBox(height: 50),
|
||||
|
||||
@@ -38,21 +38,23 @@ class _MihAddBookmarkAlertState extends State<MihAddBookmarkAlert> {
|
||||
directoryProvider,
|
||||
);
|
||||
List<Business> favBus = [];
|
||||
Map<String, ImageProvider<Object>?> favBusImages = {};
|
||||
String businessLogoUrl = "";
|
||||
// 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 = await MihFileApi.getMinioFileUrl(business.logo_path);
|
||||
favBusImages[business.business_id] =
|
||||
businessLogoUrl != "" ? NetworkImage(businessLogoUrl) : null;
|
||||
businessLogoUrl = MihFileApi.getMinioFileUrl(business.logo_path);
|
||||
favBusImages[business.business_id] = businessLogoUrl;
|
||||
// businessLogoUrl != "" ? NetworkImage(businessLogoUrl) : null;
|
||||
});
|
||||
}
|
||||
directoryProvider.setFavouriteBusinesses(
|
||||
businesses: favBus,
|
||||
businessesImages: favBusImages,
|
||||
businessesImagesUrl: favBusImages,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -43,21 +43,23 @@ class _MihDeleteBookmarkAlertState extends State<MihDeleteBookmarkAlert> {
|
||||
directoryProvider,
|
||||
);
|
||||
List<Business> favBus = [];
|
||||
Map<String, ImageProvider<Object>?> favBusImages = {};
|
||||
String businessLogoUrl = "";
|
||||
// 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 = await MihFileApi.getMinioFileUrl(business.logo_path);
|
||||
favBusImages[business.business_id] =
|
||||
businessLogoUrl != "" ? NetworkImage(businessLogoUrl) : null;
|
||||
businessLogoUrl = MihFileApi.getMinioFileUrl(business.logo_path);
|
||||
favBusImages[business.business_id] = businessLogoUrl;
|
||||
// businessLogoUrl != "" ? NetworkImage(businessLogoUrl) : null;
|
||||
});
|
||||
}
|
||||
directoryProvider.setFavouriteBusinesses(
|
||||
businesses: favBus,
|
||||
businessesImages: favBusImages,
|
||||
businessesImagesUrl: favBusImages,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ class MzansiDirectoryProvider extends ChangeNotifier {
|
||||
List<BookmarkedBusiness> bookmarkedBusinesses = [];
|
||||
List<Business>? favouriteBusinessesList;
|
||||
Map<String, ImageProvider<Object>?>? favBusImages;
|
||||
Map<String, Future<String>>? favBusImagesUrl;
|
||||
List<Business>? searchedBusinesses;
|
||||
Map<String, ImageProvider<Object>?>? busSearchImages;
|
||||
Business? selectedBusiness;
|
||||
@@ -72,10 +73,12 @@ class MzansiDirectoryProvider extends ChangeNotifier {
|
||||
|
||||
void setFavouriteBusinesses({
|
||||
required List<Business> businesses,
|
||||
required Map<String, ImageProvider<Object>?> businessesImages,
|
||||
required Map<String, Future<String>> businessesImagesUrl,
|
||||
// required Map<String, ImageProvider<Object>?> businessesImages,
|
||||
}) {
|
||||
favouriteBusinessesList = businesses;
|
||||
favBusImages = businessesImages;
|
||||
// favBusImages = businessesImages;
|
||||
favBusImagesUrl = businessesImagesUrl;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user