Clean up
This commit is contained in:
@@ -3,16 +3,12 @@ import 'package:mzansi_innovation_hub/mih_components/mih_providers/mzansi_profil
|
||||
import 'package:mzansi_innovation_hub/mih_config/mih_colors.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_packages/mzansi_profile/business_profile/components/mih_add_employee_window.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_config/mih_env.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_components/mih_objects/app_user.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class BuildUserList extends StatefulWidget {
|
||||
final List<AppUser> users;
|
||||
|
||||
const BuildUserList({
|
||||
super.key,
|
||||
required this.users,
|
||||
});
|
||||
|
||||
@override
|
||||
@@ -28,12 +24,13 @@ class _BuildUserListState extends State<BuildUserList> {
|
||||
return "$firstLetter********@$end";
|
||||
}
|
||||
|
||||
void addEmployeePopUp(int index, double width) {
|
||||
void addEmployeePopUp(
|
||||
MzansiProfileProvider profileProvider, int index, double width) {
|
||||
showDialog(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
builder: (context) => MihAddEmployeeWindow(
|
||||
user: widget.users[index],
|
||||
user: profileProvider.userSearchResults[index],
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -42,8 +39,8 @@ class _BuildUserListState extends State<BuildUserList> {
|
||||
Widget build(BuildContext context) {
|
||||
double screenWidth = MediaQuery.of(context).size.width;
|
||||
return Consumer<MzansiProfileProvider>(
|
||||
builder: (BuildContext context,
|
||||
MzansiProfileProvider mzansiProfileProvider, Widget? child) {
|
||||
builder: (BuildContext context, MzansiProfileProvider profileProvider,
|
||||
Widget? child) {
|
||||
return ListView.separated(
|
||||
shrinkWrap: true,
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
@@ -53,24 +50,25 @@ class _BuildUserListState extends State<BuildUserList> {
|
||||
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
|
||||
);
|
||||
},
|
||||
itemCount: widget.users.length,
|
||||
itemCount: profileProvider.userSearchResults.length,
|
||||
itemBuilder: (context, index) {
|
||||
var isYou = "";
|
||||
if (mzansiProfileProvider.user!.app_id ==
|
||||
widget.users[index].app_id) {
|
||||
if (profileProvider.user!.app_id ==
|
||||
profileProvider.userSearchResults[index].app_id) {
|
||||
isYou = "(You)";
|
||||
}
|
||||
return ListTile(
|
||||
title: Text("@${widget.users[index].username} $isYou"),
|
||||
title: Text(
|
||||
"@${profileProvider.userSearchResults[index].username} $isYou"),
|
||||
subtitle: Text(
|
||||
"Email: ${hideEmail(widget.users[index].email)}",
|
||||
"Email: ${hideEmail(profileProvider.userSearchResults[index].email)}",
|
||||
style: TextStyle(
|
||||
color: MihColors.getSecondaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
|
||||
),
|
||||
),
|
||||
onTap: () {
|
||||
addEmployeePopUp(index, screenWidth);
|
||||
addEmployeePopUp(profileProvider, index, screenWidth);
|
||||
},
|
||||
);
|
||||
},
|
||||
|
||||
@@ -62,6 +62,9 @@ class _MzansiBusinessProfileState extends State<MzansiBusinessProfile> {
|
||||
context.read<MzansiProfileProvider>().setBusinessIndex(2);
|
||||
};
|
||||
temp[const Icon(Icons.add)] = () {
|
||||
context
|
||||
.read<MzansiProfileProvider>()
|
||||
.setUserearchResults(userSearchResults: []);
|
||||
context.read<MzansiProfileProvider>().setBusinessIndex(3);
|
||||
};
|
||||
temp[const Icon(Icons.star_rate_rounded)] = () {
|
||||
|
||||
@@ -3,12 +3,13 @@ import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_
|
||||
import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_single_child_scroll.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_package_tool_body.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_search_bar.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_components/mih_pop_up_messages/mih_loading_circle.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_components/mih_objects/app_user.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_components/mih_providers/mzansi_profile_provider.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_config/mih_colors.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_packages/mzansi_profile/business_profile/builders/build_user_list.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_services/mih_user_services.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class MihBusinessUserSearch extends StatefulWidget {
|
||||
const MihBusinessUserSearch({
|
||||
@@ -28,25 +29,24 @@ class _MihBusinessUserSearchState extends State<MihBusinessUserSearch> {
|
||||
String errorCode = "";
|
||||
String errorBody = "";
|
||||
|
||||
Future<List<AppUser>> fetchUsers(String search) async {
|
||||
return MihUserServices().searchUsers(search, context);
|
||||
Future<List<AppUser>> fetchUsers(
|
||||
MzansiProfileProvider profileProvider, String search) async {
|
||||
return MihUserServices().searchUsers(profileProvider, search, context);
|
||||
}
|
||||
|
||||
void submitUserForm() {
|
||||
void submitUserForm(MzansiProfileProvider profileProvider) {
|
||||
if (searchController.text != "") {
|
||||
setState(() {
|
||||
userSearch = searchController.text;
|
||||
hasSearchedBefore = true;
|
||||
userSearchResults = fetchUsers(userSearch);
|
||||
userSearchResults = fetchUsers(profileProvider, userSearch);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Widget displayUserList(List<AppUser> userList) {
|
||||
if (userList.isNotEmpty) {
|
||||
return BuildUserList(
|
||||
users: userList,
|
||||
);
|
||||
Widget displayUserList(MzansiProfileProvider profileProvider) {
|
||||
if (profileProvider.userSearchResults.isNotEmpty) {
|
||||
return BuildUserList();
|
||||
}
|
||||
if (hasSearchedBefore && userSearch.isNotEmpty) {
|
||||
return Column(
|
||||
@@ -145,7 +145,6 @@ class _MihBusinessUserSearchState extends State<MihBusinessUserSearch> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
userSearchResults = fetchUsers("abc");
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -168,63 +167,41 @@ class _MihBusinessUserSearchState extends State<MihBusinessUserSearch> {
|
||||
|
||||
Widget getBody(double width) {
|
||||
// dscvds
|
||||
return MihSingleChildScroll(
|
||||
child: Column(mainAxisSize: MainAxisSize.max, children: [
|
||||
Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: width / 20),
|
||||
child: MihSearchBar(
|
||||
controller: searchController,
|
||||
hintText: "Search Users",
|
||||
prefixIcon: Icons.search,
|
||||
fillColor: MihColors.getSecondaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
|
||||
hintColor: MihColors.getPrimaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
|
||||
onPrefixIconTap: () {
|
||||
submitUserForm();
|
||||
},
|
||||
onClearIconTap: () {
|
||||
setState(() {
|
||||
searchController.clear();
|
||||
userSearch = "";
|
||||
});
|
||||
},
|
||||
searchFocusNode: _searchFocusNode,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
FutureBuilder(
|
||||
future: userSearchResults,
|
||||
builder: (context, snapshot) {
|
||||
//print("patient Liust ${snapshot.data}");
|
||||
if (snapshot.connectionState == ConnectionState.waiting) {
|
||||
return const Mihloadingcircle();
|
||||
} else if (snapshot.connectionState == ConnectionState.done &&
|
||||
snapshot.hasData) {
|
||||
List<AppUser> patientsList;
|
||||
if (userSearch == "") {
|
||||
patientsList = [];
|
||||
} else {
|
||||
patientsList = snapshot.data!;
|
||||
//print(patientsList);
|
||||
}
|
||||
return displayUserList(patientsList);
|
||||
} else {
|
||||
return Center(
|
||||
child: Text(
|
||||
"$errorCode: Error pulling Patients Data\n/users/search/$userSearch\n$errorBody",
|
||||
style: TextStyle(
|
||||
fontSize: 25,
|
||||
color: MihColors.getRedColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode ==
|
||||
"Dark")),
|
||||
textAlign: TextAlign.center,
|
||||
return Consumer<MzansiProfileProvider>(
|
||||
builder: (BuildContext context, MzansiProfileProvider profileProvider,
|
||||
Widget? child) {
|
||||
return MihSingleChildScroll(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
children: [
|
||||
Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: width / 20),
|
||||
child: MihSearchBar(
|
||||
controller: searchController,
|
||||
hintText: "Search Users",
|
||||
prefixIcon: Icons.search,
|
||||
fillColor: MihColors.getSecondaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
|
||||
hintColor: MihColors.getPrimaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
|
||||
onPrefixIconTap: () {
|
||||
submitUserForm(profileProvider);
|
||||
},
|
||||
onClearIconTap: () {
|
||||
setState(() {
|
||||
searchController.clear();
|
||||
userSearch = "";
|
||||
});
|
||||
},
|
||||
searchFocusNode: _searchFocusNode,
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
]),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
displayUserList(profileProvider),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user