BUG: fav bus view fix performace pt 2

This commit is contained in:
2025-11-28 11:33:26 +02:00
parent 3b6e1d22ec
commit 3d2addf1d6
4 changed files with 327 additions and 328 deletions

View File

@@ -27,8 +27,8 @@ class _BuildBusinessSearchResultsListState
builder: (BuildContext context, MzansiDirectoryProvider directoryProvider, builder: (BuildContext context, MzansiDirectoryProvider directoryProvider,
Widget? child) { Widget? child) {
return ListView.separated( return ListView.separated(
shrinkWrap: true, // shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(), // physics: const NeverScrollableScrollPhysics(),
itemCount: widget.businessList.length, itemCount: widget.businessList.length,
separatorBuilder: (BuildContext context, index) { separatorBuilder: (BuildContext context, index) {
return Divider( return Divider(

View File

@@ -27,8 +27,8 @@ class _BuildUserSearchResultsListState
builder: (BuildContext context, MzansiDirectoryProvider directoryProvider, builder: (BuildContext context, MzansiDirectoryProvider directoryProvider,
Widget? child) { Widget? child) {
return ListView.separated( return ListView.separated(
shrinkWrap: true, // shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(), // physics: const NeverScrollableScrollPhysics(),
itemCount: widget.userList.length, itemCount: widget.userList.length,
separatorBuilder: (BuildContext context, index) { separatorBuilder: (BuildContext context, index) {
return Divider( return Divider(

View File

@@ -1,3 +1,4 @@
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:geolocator/geolocator.dart'; import 'package:geolocator/geolocator.dart';
import 'package:go_router/go_router.dart'; import 'package:go_router/go_router.dart';
@@ -30,6 +31,8 @@ class _MzansiDirectoryState extends State<MzansiDirectory> {
bool _isLoadingInitialData = true; bool _isLoadingInitialData = true;
late Future<Position?> futurePosition = late Future<Position?> futurePosition =
MIHLocationAPI().getGPSPosition(context); MIHLocationAPI().getGPSPosition(context);
late final MihSearchMzansi _searchTool;
late final MihFavouriteBusinesses _favouritesTool;
Future<void> _loadInitialData() async { Future<void> _loadInitialData() async {
setState(() { setState(() {
@@ -72,8 +75,9 @@ class _MzansiDirectoryState extends State<MzansiDirectory> {
.then((business) async { .then((business) async {
favBus.add(business!); favBus.add(business!);
businessLogoUrl = await MihFileApi.getMinioFileUrl(business.logo_path); businessLogoUrl = await MihFileApi.getMinioFileUrl(business.logo_path);
favBusImages[business.business_id] = favBusImages[business.business_id] = businessLogoUrl != ""
businessLogoUrl != "" ? NetworkImage(businessLogoUrl) : null; ? CachedNetworkImageProvider(businessLogoUrl)
: null;
}); });
} }
directoryProvider.setFavouriteBusinesses( directoryProvider.setFavouriteBusinesses(
@@ -133,6 +137,8 @@ class _MzansiDirectoryState extends State<MzansiDirectory> {
@override @override
void initState() { void initState() {
super.initState(); super.initState();
_searchTool = const MihSearchMzansi();
_favouritesTool = const MihFavouriteBusinesses();
_loadInitialData(); _loadInitialData();
} }
@@ -163,12 +169,10 @@ class _MzansiDirectoryState extends State<MzansiDirectory> {
} }
List<Widget> getToolBody() { List<Widget> getToolBody() {
List<Widget> toolBodies = []; return [
toolBodies.addAll([ _searchTool,
MihSearchMzansi(), _favouritesTool,
MihFavouriteBusinesses(), ];
]);
return toolBodies;
} }
MihPackageAction getAction() { MihPackageAction getAction() {

View File

@@ -1,3 +1,4 @@
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:ken_logger/ken_logger.dart'; import 'package:ken_logger/ken_logger.dart';
import 'package:mzansi_innovation_hub/main.dart'; import 'package:mzansi_innovation_hub/main.dart';
@@ -86,8 +87,9 @@ class _MihSearchMzansiState extends State<MihSearchMzansi> {
KenLogger.success("Business Logo Path: ${user.pro_pic_path}"); KenLogger.success("Business Logo Path: ${user.pro_pic_path}");
usernProPicUrl = await MihFileApi.getMinioFileUrl(user.pro_pic_path); usernProPicUrl = await MihFileApi.getMinioFileUrl(user.pro_pic_path);
KenLogger.success("Business Logo Path: ${user.pro_pic_path}"); KenLogger.success("Business Logo Path: ${user.pro_pic_path}");
userImages[user.app_id] = userImages[user.app_id] = usernProPicUrl != ""
usernProPicUrl != "" ? NetworkImage(usernProPicUrl) : null; ? CachedNetworkImageProvider(usernProPicUrl)
: null;
} }
directoryProvider.setSearchedUsers( directoryProvider.setSearchedUsers(
@@ -111,8 +113,9 @@ class _MihSearchMzansiState extends State<MihSearchMzansi> {
KenLogger.success("Business Logo Path: ${bus.logo_path}"); KenLogger.success("Business Logo Path: ${bus.logo_path}");
businessLogoUrl = await MihFileApi.getMinioFileUrl(bus.logo_path); businessLogoUrl = await MihFileApi.getMinioFileUrl(bus.logo_path);
KenLogger.success("Business Logo Path: ${bus.logo_path}"); KenLogger.success("Business Logo Path: ${bus.logo_path}");
busImages[bus.business_id] = busImages[bus.business_id] = businessLogoUrl != ""
businessLogoUrl != "" ? NetworkImage(businessLogoUrl) : null; ? CachedNetworkImageProvider(businessLogoUrl)
: null;
} }
directoryProvider.setSearchedBusinesses( directoryProvider.setSearchedBusinesses(
searchedBusinesses: businessSearchResults, searchedBusinesses: businessSearchResults,
@@ -158,9 +161,15 @@ class _MihSearchMzansiState extends State<MihSearchMzansi> {
return Consumer2<MzansiProfileProvider, MzansiDirectoryProvider>( return Consumer2<MzansiProfileProvider, MzansiDirectoryProvider>(
builder: (BuildContext context, MzansiProfileProvider profileProvider, builder: (BuildContext context, MzansiProfileProvider profileProvider,
MzansiDirectoryProvider directoryProvider, Widget? child) { MzansiDirectoryProvider directoryProvider, Widget? child) {
return MihSingleChildScroll( return Column(
child: Column(
children: [ children: [
Text(
directoryProvider.personalSearch
? "People Search"
: "Businesses Search",
style: TextStyle(fontSize: 25, fontWeight: FontWeight.bold),
),
const SizedBox(height: 10),
Padding( Padding(
padding: EdgeInsets.symmetric(horizontal: width / 20), padding: EdgeInsets.symmetric(horizontal: width / 20),
child: Row( child: Row(
@@ -295,9 +304,12 @@ class _MihSearchMzansiState extends State<MihSearchMzansi> {
); );
}), }),
const SizedBox(height: 10), const SizedBox(height: 10),
displaySearchResults(directoryProvider), Expanded(
], child: directoryProvider.personalSearch
? displayPersonalSearchResults(directoryProvider)
: displayBusinessSearchResults(directoryProvider),
), ),
],
); );
}, },
); );
@@ -313,22 +325,13 @@ class _MihSearchMzansiState extends State<MihSearchMzansi> {
// return Text("Pulled Data successfully"); // return Text("Pulled Data successfully");
directoryProvider.searchedBusinesses! directoryProvider.searchedBusinesses!
.sort((a, b) => a.Name.compareTo(b.Name)); .sort((a, b) => a.Name.compareTo(b.Name));
return Column( return BuildBusinessSearchResultsList(
children: [
Text(
"Businesses of Mzansi",
style: TextStyle(fontSize: 25, fontWeight: FontWeight.bold),
),
const SizedBox(height: 10),
BuildBusinessSearchResultsList(
businessList: directoryProvider.searchedBusinesses!, businessList: directoryProvider.searchedBusinesses!,
),
],
); );
} else if (directoryProvider.searchedBusinesses!.isEmpty && } else if (directoryProvider.searchedBusinesses!.isEmpty &&
directoryProvider.searchTerm.isNotEmpty) { directoryProvider.searchTerm.isNotEmpty) {
// return Text("Pulled Data successfully"); return MihSingleChildScroll(
return Column( child: Column(
children: [ children: [
const SizedBox(height: 50), const SizedBox(height: 50),
Icon( Icon(
@@ -350,10 +353,12 @@ class _MihSearchMzansiState extends State<MihSearchMzansi> {
), ),
), ),
], ],
),
); );
} else if (directoryProvider.searchedBusinesses!.isEmpty && } else if (directoryProvider.searchedBusinesses!.isEmpty &&
directoryProvider.searchTerm.isEmpty) { directoryProvider.searchTerm.isEmpty) {
return Padding( return MihSingleChildScroll(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 10.0), padding: const EdgeInsets.symmetric(horizontal: 10.0),
child: Column( child: Column(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
@@ -387,7 +392,8 @@ class _MihSearchMzansiState extends State<MihSearchMzansi> {
fontSize: 20, fontSize: 20,
fontWeight: FontWeight.normal, fontWeight: FontWeight.normal,
color: MihColors.getSecondaryColor( color: MihColors.getSecondaryColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"), MzansiInnovationHub.of(context)!.theme.mode ==
"Dark"),
), ),
children: [ children: [
TextSpan(text: "Press "), TextSpan(text: "Press "),
@@ -415,7 +421,8 @@ class _MihSearchMzansiState extends State<MihSearchMzansi> {
fontSize: 20, fontSize: 20,
fontWeight: FontWeight.normal, fontWeight: FontWeight.normal,
color: MihColors.getSecondaryColor( color: MihColors.getSecondaryColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"), MzansiInnovationHub.of(context)!.theme.mode ==
"Dark"),
), ),
children: [ children: [
TextSpan(text: "Press "), TextSpan(text: "Press "),
@@ -436,6 +443,7 @@ class _MihSearchMzansiState extends State<MihSearchMzansi> {
), ),
], ],
), ),
),
); );
} else { } else {
return Center( return Center(
@@ -458,23 +466,14 @@ class _MihSearchMzansiState extends State<MihSearchMzansi> {
child: const Mihloadingcircle(), child: const Mihloadingcircle(),
); );
} else if (directoryProvider.searchedUsers!.isNotEmpty) { } else if (directoryProvider.searchedUsers!.isNotEmpty) {
// return Text("Pulled Data successfully");
directoryProvider.searchedUsers! directoryProvider.searchedUsers!
.sort((a, b) => a.username.compareTo(b.username)); .sort((a, b) => a.username.compareTo(b.username));
return Column( return BuildUserSearchResultsList(
children: [ userList: directoryProvider.searchedUsers!);
Text(
"People of Mzansi",
style: TextStyle(fontSize: 25, fontWeight: FontWeight.bold),
),
const SizedBox(height: 10),
BuildUserSearchResultsList(
userList: directoryProvider.searchedUsers!),
],
);
} else if (directoryProvider.searchedUsers!.isEmpty && } else if (directoryProvider.searchedUsers!.isEmpty &&
directoryProvider.searchTerm.isEmpty) { directoryProvider.searchTerm.isEmpty) {
return Padding( return MihSingleChildScroll(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 10.0), padding: const EdgeInsets.symmetric(horizontal: 10.0),
child: Column( child: Column(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
@@ -508,7 +507,8 @@ class _MihSearchMzansiState extends State<MihSearchMzansi> {
fontSize: 20, fontSize: 20,
fontWeight: FontWeight.normal, fontWeight: FontWeight.normal,
color: MihColors.getSecondaryColor( color: MihColors.getSecondaryColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"), MzansiInnovationHub.of(context)!.theme.mode ==
"Dark"),
), ),
children: [ children: [
TextSpan(text: "Press "), TextSpan(text: "Press "),
@@ -529,10 +529,12 @@ class _MihSearchMzansiState extends State<MihSearchMzansi> {
), ),
], ],
), ),
),
); );
} else if (directoryProvider.searchedUsers!.isEmpty && } else if (directoryProvider.searchedUsers!.isEmpty &&
directoryProvider.searchTerm.isNotEmpty) { directoryProvider.searchTerm.isNotEmpty) {
return Column( return MihSingleChildScroll(
child: Column(
children: [ children: [
const SizedBox(height: 50), const SizedBox(height: 50),
Icon( Icon(
@@ -554,6 +556,7 @@ class _MihSearchMzansiState extends State<MihSearchMzansi> {
), ),
), ),
], ],
),
); );
} else { } else {
return Center( return Center(
@@ -568,12 +571,4 @@ class _MihSearchMzansiState extends State<MihSearchMzansi> {
); );
} }
} }
Widget displaySearchResults(MzansiDirectoryProvider directoryProvider) {
if (directoryProvider.personalSearch) {
return displayPersonalSearchResults(directoryProvider);
} else {
return displayBusinessSearchResults(directoryProvider);
}
}
} }