QOL: Data display load Mzansi Direct pt2

This commit is contained in:
2025-12-03 10:51:18 +02:00
parent 456dff6402
commit a6d5e4ad35
6 changed files with 119 additions and 57 deletions

View File

@@ -3,14 +3,17 @@ import 'package:mzansi_innovation_hub/main.dart';
import 'package:mzansi_innovation_hub/mih_objects/app_user.dart';
import 'package:mzansi_innovation_hub/mih_package_components/mih_circle_avatar.dart';
import 'package:mzansi_innovation_hub/mih_config/mih_colors.dart';
import 'package:mzansi_innovation_hub/mih_package_components/mih_icons.dart';
class MihPersonalProfilePreview extends StatefulWidget {
final AppUser user;
final ImageProvider<Object>? imageFile;
final bool loading;
const MihPersonalProfilePreview({
super.key,
required this.user,
required this.imageFile,
required this.loading,
});
@override
@@ -29,18 +32,32 @@ class _MihPersonalProfilePreviewState extends State<MihPersonalProfilePreview> {
double profilePictureWidth = 60;
return Row(
children: [
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.loading
? Icon(
MihIcons.mihRing,
size: profilePictureWidth,
color: MihColors.getSecondaryColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
)
: 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,

View File

@@ -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';
@@ -58,13 +59,32 @@ class _BuildBusinessSearchResultsListState
// vertical: 5,
horizontal: 25,
),
child: MihBusinessProfilePreview(
business: widget.businessList[index],
imageFile: directoryProvider.busSearchImages![
widget.businessList[index].business_id],
loading: false,
//To Do
),
child: FutureBuilder(
future: directoryProvider.busSearchImagesUrl![
widget.businessList[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.businessList[index],
imageFile: imageFile,
loading: loading,
);
}),
),
),
);

View File

@@ -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';
@@ -57,11 +58,32 @@ class _BuildUserSearchResultsListState
// vertical: 5,
horizontal: 25,
),
child: MihPersonalProfilePreview(
user: widget.userList[index],
imageFile: directoryProvider
.userSearchImages![widget.userList[index].app_id],
),
child: FutureBuilder(
future: directoryProvider
.userSearchImagesUrl![widget.userList[index].app_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 MihPersonalProfilePreview(
user: widget.userList[index],
imageFile: imageFile,
loading: loading,
);
}),
),
),
);

View File

@@ -1,4 +1,3 @@
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:ken_logger/ken_logger.dart';
import 'package:mzansi_innovation_hub/main.dart';
@@ -60,8 +59,8 @@ class _MihSearchMzansiState extends State<MihSearchMzansi> {
void clearAll(MzansiDirectoryProvider directoryProvider) {
directoryProvider
.setSearchedBusinesses(searchedBusinesses: [], businessesImages: {});
directoryProvider.setSearchedUsers(searchedUsers: [], userImages: {});
.setSearchedBusinesses(searchedBusinesses: [], businessesImagesUrl: {});
directoryProvider.setSearchedUsers(searchedUsers: [], userImagesUrl: {});
directoryProvider.setSearchTerm(searchTerm: "");
setState(() {
mzansiSearchController.clear();
@@ -81,20 +80,21 @@ class _MihSearchMzansiState extends State<MihSearchMzansi> {
directoryProvider.searchTerm.isNotEmpty) {
final userResults = await MihUserServices()
.searchUsers(profileProvider, directoryProvider.searchTerm, context);
Map<String, ImageProvider<Object>?> userImages = {};
String usernProPicUrl = "";
Map<String, Future<String>> userImages = {};
Future<String> usernProPicUrl;
for (var user in userResults) {
KenLogger.success("Business Logo Path: ${user.pro_pic_path}");
usernProPicUrl = await MihFileApi.getMinioFileUrl(user.pro_pic_path);
usernProPicUrl = MihFileApi.getMinioFileUrl(user.pro_pic_path);
KenLogger.success("Business Logo Path: ${user.pro_pic_path}");
userImages[user.app_id] = usernProPicUrl != ""
? CachedNetworkImageProvider(usernProPicUrl)
: null;
userImages[user.app_id] = usernProPicUrl;
// != ""
// ? CachedNetworkImageProvider(usernProPicUrl)
// : null;
}
directoryProvider.setSearchedUsers(
searchedUsers: userResults,
userImages: userImages,
userImagesUrl: userImages,
);
} else {
List<Business>? businessSearchResults = [];
@@ -107,19 +107,20 @@ class _MihSearchMzansiState extends State<MihSearchMzansi> {
.searchBusinesses(directoryProvider.searchTerm,
directoryProvider.businessTypeFilter, context);
}
Map<String, ImageProvider<Object>?> busImages = {};
String businessLogoUrl = "";
Map<String, Future<String>> busImagesUrl = {};
Future<String> businessLogoUrl;
for (var bus in businessSearchResults) {
KenLogger.success("Business Logo Path: ${bus.logo_path}");
businessLogoUrl = await MihFileApi.getMinioFileUrl(bus.logo_path);
businessLogoUrl = MihFileApi.getMinioFileUrl(bus.logo_path);
KenLogger.success("Business Logo Path: ${bus.logo_path}");
busImages[bus.business_id] = businessLogoUrl != ""
? CachedNetworkImageProvider(businessLogoUrl)
: null;
busImagesUrl[bus.business_id] = businessLogoUrl;
// != ""
// ? CachedNetworkImageProvider(businessLogoUrl)
// : null;
}
directoryProvider.setSearchedBusinesses(
searchedBusinesses: businessSearchResults,
businessesImages: busImages,
businessesImagesUrl: busImagesUrl,
);
}
setState(() {
@@ -143,7 +144,10 @@ class _MihSearchMzansiState extends State<MihSearchMzansi> {
MihBusinessDetailsServices().fetchAllBusinessTypes();
mzansiSearchController.text = "";
WidgetsBinding.instance.addPostFrameCallback((_) async {
directoryProvider.setSearchedUsers(searchedUsers: [], userImages: {});
directoryProvider.setSearchedUsers(
searchedUsers: [],
userImagesUrl: {},
);
});
}

View File

@@ -574,16 +574,18 @@ class _MihBusinessCardState extends State<MihBusinessCard> {
businessSearchResults = await MihBusinessDetailsServices()
.searchBusinesses(directoryProvider.searchTerm,
directoryProvider.businessTypeFilter, context);
Map<String, ImageProvider<Object>?> busImages = {};
String businessLogoUrl = "";
// Map<String, ImageProvider<Object>?> busImages = {};
Map<String, Future<String>> busImagesUrl = {};
// String businessLogoUrl = "";
Future<String> businessLogoUrl;
for (var bus in businessSearchResults) {
businessLogoUrl = await MihFileApi.getMinioFileUrl(bus.logo_path);
busImages[bus.business_id] =
businessLogoUrl != "" ? NetworkImage(businessLogoUrl) : null;
businessLogoUrl = MihFileApi.getMinioFileUrl(bus.logo_path);
busImagesUrl[bus.business_id] = businessLogoUrl;
// != "" ? NetworkImage(businessLogoUrl) : null;
}
directoryProvider.setSearchedBusinesses(
searchedBusinesses: businessSearchResults,
businessesImages: busImages,
businessesImagesUrl: busImagesUrl,
);
setState(() {
_businessReviewFuture = getUserReview();

View File

@@ -11,13 +11,12 @@ class MzansiDirectoryProvider extends ChangeNotifier {
bool personalSearch;
List<BookmarkedBusiness> bookmarkedBusinesses = [];
List<Business>? favouriteBusinessesList;
Map<String, ImageProvider<Object>?>? favBusImages;
Map<String, Future<String>>? favBusImagesUrl;
List<Business>? searchedBusinesses;
Map<String, ImageProvider<Object>?>? busSearchImages;
Map<String, Future<String>>? busSearchImagesUrl;
Business? selectedBusiness;
List<AppUser>? searchedUsers;
Map<String, ImageProvider<Object>?>? userSearchImages;
Map<String, Future<String>>? userSearchImagesUrl;
AppUser? selectedUser;
String searchTerm;
String businessTypeFilter;
@@ -74,20 +73,18 @@ class MzansiDirectoryProvider extends ChangeNotifier {
void setFavouriteBusinesses({
required List<Business> businesses,
required Map<String, Future<String>> businessesImagesUrl,
// required Map<String, ImageProvider<Object>?> businessesImages,
}) {
favouriteBusinessesList = businesses;
// favBusImages = businessesImages;
favBusImagesUrl = businessesImagesUrl;
notifyListeners();
}
void setSearchedBusinesses({
required List<Business> searchedBusinesses,
required Map<String, ImageProvider<Object>?> businessesImages,
required Map<String, Future<String>> businessesImagesUrl,
}) {
this.searchedBusinesses = searchedBusinesses;
busSearchImages = businessesImages;
busSearchImagesUrl = businessesImagesUrl;
notifyListeners();
}
@@ -98,10 +95,10 @@ class MzansiDirectoryProvider extends ChangeNotifier {
void setSearchedUsers({
required List<AppUser> searchedUsers,
required Map<String, ImageProvider<Object>?> userImages,
required Map<String, Future<String>> userImagesUrl,
}) {
this.searchedUsers = searchedUsers;
this.userSearchImages = userImages;
this.userSearchImagesUrl = userImagesUrl;
notifyListeners();
}