From 4f780ad0aa32851fd8546483acaaec163401f8d6 Mon Sep 17 00:00:00 2001 From: "Aamir.Muhammad" Date: Tue, 27 Dec 2022 08:29:26 +0300 Subject: [PATCH 1/4] Fixes --- lib/classes/consts.dart | 4 +- lib/provider/chat_provider_model.dart | 75 +++++++++++++++------------ lib/ui/chat/my_team_screen.dart | 20 +++---- 3 files changed, 54 insertions(+), 45 deletions(-) diff --git a/lib/classes/consts.dart b/lib/classes/consts.dart index 6679cbb..900fd4a 100644 --- a/lib/classes/consts.dart +++ b/lib/classes/consts.dart @@ -3,8 +3,8 @@ import 'package:mohem_flutter_app/ui/marathon/widgets/question_card.dart'; class ApiConsts { //static String baseUrl = "http://10.200.204.20:2801/"; // Local server // static String baseUrl = "https://erptstapp.srca.org.sa"; // SRCA server - static String baseUrl = "https://uat.hmgwebservices.com"; // UAT server - // static String baseUrl = "https://hmgwebservices.com"; // Live server + //static String baseUrl = "https://uat.hmgwebservices.com"; // UAT server + static String baseUrl = "https://hmgwebservices.com"; // Live server static String baseUrlServices = baseUrl + "/Services/"; // server // static String baseUrlServices = "https://api.cssynapses.com/tangheem/"; // Live server static String utilitiesRest = baseUrlServices + "Utilities.svc/REST/"; diff --git a/lib/provider/chat_provider_model.dart b/lib/provider/chat_provider_model.dart index 24c4532..f46b958 100644 --- a/lib/provider/chat_provider_model.dart +++ b/lib/provider/chat_provider_model.dart @@ -330,6 +330,8 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { user.userStatus = items.first["userStatus"]; } } + + notifyListeners(); } @@ -1292,45 +1294,52 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { print("=============== In App State ====================="); getEmployeeSubordinatesList = AppState().getemployeeSubordinatesList; for (GetEmployeeSubordinatesList element in getEmployeeSubordinatesList) { - print(element.eMPLOYEEEMAILADDRESS); - teamMembersList.add( - ChatUser( - id: int.parse(element.eMPLOYEENUMBER!), - email: element.eMPLOYEEEMAILADDRESS, - userName: element.eMPLOYEEDISPLAYNAME, - phone: element.eMPLOYEEMOBILENUMBER, - userStatus: 0, - unreadMessageCount: 0, - isFav: false, - isTyping: false, - isImageLoading: false, - image: element.eMPLOYEEIMAGE ?? "", - isImageLoaded: true, - userLocalDownlaodedImage: await downloadImageLocal(element.eMPLOYEEIMAGE ?? "", element.eMPLOYEENUMBER!), - ), - ); + if (element.eMPLOYEEEMAILADDRESS != null) { + if (element.eMPLOYEEEMAILADDRESS!.isNotEmpty) { + teamMembersList.add( + ChatUser( + id: int.parse(element.eMPLOYEENUMBER!), + email: element.eMPLOYEEEMAILADDRESS, + userName: element.eMPLOYEEDISPLAYNAME, + phone: element.eMPLOYEEMOBILENUMBER, + userStatus: 0, + unreadMessageCount: 0, + isFav: false, + isTyping: false, + isImageLoading: false, + image: element.eMPLOYEEIMAGE ?? "", + isImageLoaded: true, + userLocalDownlaodedImage: await downloadImageLocal(element.eMPLOYEEIMAGE ?? "", element.eMPLOYEENUMBER!), + ), + ); + } + } } } else { getEmployeeSubordinatesList = await MyTeamApiClient().getEmployeeSubordinates("", "", ""); AppState().setemployeeSubordinatesList = getEmployeeSubordinatesList; for (GetEmployeeSubordinatesList element in getEmployeeSubordinatesList) { print(element.eMPLOYEEEMAILADDRESS); - teamMembersList.add( - ChatUser( - id: int.parse(element.eMPLOYEENUMBER!), - email: element.eMPLOYEEEMAILADDRESS, - userName: element.eMPLOYEEDISPLAYNAME, - phone: element.eMPLOYEEMOBILENUMBER, - userStatus: 0, - unreadMessageCount: 0, - isFav: false, - isTyping: false, - isImageLoading: false, - image: element.eMPLOYEEIMAGE ?? "", - isImageLoaded: true, - userLocalDownlaodedImage: await downloadImageLocal(element.eMPLOYEEIMAGE ?? "", element.eMPLOYEENUMBER!), - ), - ); + if (element.eMPLOYEEEMAILADDRESS != null) { + if (element.eMPLOYEEEMAILADDRESS!.isNotEmpty) { + teamMembersList.add( + ChatUser( + id: int.parse(element.eMPLOYEENUMBER!), + email: element.eMPLOYEEEMAILADDRESS, + userName: element.eMPLOYEEDISPLAYNAME, + phone: element.eMPLOYEEMOBILENUMBER, + userStatus: 0, + unreadMessageCount: 0, + isFav: false, + isTyping: false, + isImageLoading: false, + image: element.eMPLOYEEIMAGE ?? "", + isImageLoaded: true, + userLocalDownlaodedImage: await downloadImageLocal(element.eMPLOYEEIMAGE ?? "", element.eMPLOYEENUMBER!), + ), + ); + } + } } } isLoading = false; diff --git a/lib/ui/chat/my_team_screen.dart b/lib/ui/chat/my_team_screen.dart index 6b68a58..3f59ab2 100644 --- a/lib/ui/chat/my_team_screen.dart +++ b/lib/ui/chat/my_team_screen.dart @@ -128,16 +128,16 @@ class _MyTeamScreenState extends State { ], ), ).onPress(() { - print(jsonEncode(m.teamMembersList[index])); - // Navigator.pushNamed( - // context, - // AppRoutes.chatDetailed, - // arguments: ChatDetailedScreenParams(m.teamMembersList![index], true), - // ).then( - // (Object? value) { - // m.clearSelections(); - // }, - // ); + // print(jsonEncode(m.teamMembersList[index])); + Navigator.pushNamed( + context, + AppRoutes.chatDetailed, + arguments: ChatDetailedScreenParams(m.teamMembersList![index], true), + ).then( + (Object? value) { + m.clearSelections(); + }, + ); }); }, separatorBuilder: (BuildContext context, int index) => const Divider(color: MyColors.lightGreyE5Color).paddingOnly(left: 70), From 3871d3f1e389f958a3eb4a510a4c5b532c29bea7 Mon Sep 17 00:00:00 2001 From: "Aamir.Muhammad" Date: Tue, 27 Dec 2022 14:28:08 +0300 Subject: [PATCH 2/4] Fixes --- lib/api/chat/chat_api_client.dart | 12 +- lib/classes/consts.dart | 2 +- .../chat/get_search_user_chat_model.dart | 54 +- lib/provider/chat_provider_model.dart | 13 +- lib/ui/chat/chat_home_screen.dart | 1 + .../search_employee_bottom_sheet.dart | 475 ++++++++++-------- .../shimmer/dashboard_shimmer_widget.dart | 6 +- 7 files changed, 326 insertions(+), 237 deletions(-) diff --git a/lib/api/chat/chat_api_client.dart b/lib/api/chat/chat_api_client.dart index 43e9f6c..87e684e 100644 --- a/lib/api/chat/chat_api_client.dart +++ b/lib/api/chat/chat_api_client.dart @@ -46,15 +46,15 @@ class ChatApiClient { return userLoginResponse; } - Future?> getChatMemberFromSearch(String sName, int cUserId) async { - Response response = await ApiClient().getJsonForResponse( - "${ApiConsts.chatLoginTokenUrl}getUserWithStatusAndFavAsync/$sName/$cUserId", - token: AppState().chatDetails!.response!.token, - ); + Future getChatMemberFromSearch(String searchParam, int cUserId, int pageNo) async { + ChatUserModel chatUserModel; + Response response = await ApiClient().postJsonForResponse("${ApiConsts.chatLoginTokenUrl}getUserWithStatusAndFavAsync", {"employeeNumber": cUserId, "userName": searchParam, "pageNumber": pageNo}, + token: AppState().chatDetails!.response!.token); if (!kReleaseMode) { logger.i("res: " + response.body); } - return List.from(json.decode(response.body).map((x) => ChatUser.fromJson(x))); + chatUserModel = chatUserModelFromJson(response.body); + return chatUserModel; } //Get User Recent Chats diff --git a/lib/classes/consts.dart b/lib/classes/consts.dart index 900fd4a..990656f 100644 --- a/lib/classes/consts.dart +++ b/lib/classes/consts.dart @@ -3,7 +3,7 @@ import 'package:mohem_flutter_app/ui/marathon/widgets/question_card.dart'; class ApiConsts { //static String baseUrl = "http://10.200.204.20:2801/"; // Local server // static String baseUrl = "https://erptstapp.srca.org.sa"; // SRCA server - //static String baseUrl = "https://uat.hmgwebservices.com"; // UAT server + // static String baseUrl = "https://uat.hmgwebservices.com"; // UAT server static String baseUrl = "https://hmgwebservices.com"; // Live server static String baseUrlServices = baseUrl + "/Services/"; // server // static String baseUrlServices = "https://api.cssynapses.com/tangheem/"; // Live server diff --git a/lib/models/chat/get_search_user_chat_model.dart b/lib/models/chat/get_search_user_chat_model.dart index 3d023fd..e1c87a3 100644 --- a/lib/models/chat/get_search_user_chat_model.dart +++ b/lib/models/chat/get_search_user_chat_model.dart @@ -1,5 +1,11 @@ + +import 'dart:convert'; import 'dart:io'; +ChatUserModel chatUserModelFromJson(String str) => ChatUserModel.fromJson(json.decode(str)); + +String chatUserModelToJson(ChatUserModel data) => json.encode(data.toJson()); + class ChatUserModel { ChatUserModel({ this.response, @@ -7,16 +13,40 @@ class ChatUserModel { }); List? response; - dynamic errorResponses; + List? errorResponses; factory ChatUserModel.fromJson(Map json) => ChatUserModel( response: json["response"] == null ? null : List.from(json["response"].map((x) => ChatUser.fromJson(x))), - errorResponses: json["errorResponses"], + errorResponses: json["errorResponses"] == null ? null : List.from(json["errorResponses"].map((x) => ErrorResponse.fromJson(x))), ); Map toJson() => { "response": response == null ? null : List.from(response!.map((x) => x.toJson())), - "errorResponses": errorResponses, + "errorResponses": errorResponses == null ? null : List.from(errorResponses!.map((x) => x.toJson())), + }; +} + +class ErrorResponse { + ErrorResponse({ + this.fieldName, + this.message, + }); + + dynamic? fieldName; + String? message; + + factory ErrorResponse.fromRawJson(String str) => ErrorResponse.fromJson(json.decode(str)); + + String toRawJson() => json.encode(toJson()); + + factory ErrorResponse.fromJson(Map json) => ErrorResponse( + fieldName: json["fieldName"], + message: json["message"] == null ? null : json["message"], + ); + + Map toJson() => { + "fieldName": fieldName, + "message": message == null ? null : message, }; } @@ -34,6 +64,8 @@ class ChatUser { this.isPin, this.isFav, this.isAdmin, + this.rKey, + this.totalCount, this.isTyping, this.isImageLoaded, this.isImageLoading, @@ -44,7 +76,7 @@ class ChatUser { String? userName; String? email; dynamic? phone; - dynamic? title; + String? title; int? userStatus; dynamic? image; int? unreadMessageCount; @@ -52,17 +84,23 @@ class ChatUser { bool? isPin; bool? isFav; bool? isAdmin; + dynamic? rKey; + int? totalCount; bool? isTyping; bool? isImageLoaded; bool? isImageLoading; File? userLocalDownlaodedImage; + factory ChatUser.fromRawJson(String str) => ChatUser.fromJson(json.decode(str)); + + String toRawJson() => json.encode(toJson()); + factory ChatUser.fromJson(Map json) => ChatUser( id: json["id"] == null ? null : json["id"], userName: json["userName"] == null ? null : json["userName"], email: json["email"] == null ? null : json["email"], phone: json["phone"], - title: json["title"], + title: json["title"] == null ? null : json["title"], userStatus: json["userStatus"] == null ? null : json["userStatus"], image: json["image"], unreadMessageCount: json["unreadMessageCount"] == null ? null : json["unreadMessageCount"], @@ -70,6 +108,8 @@ class ChatUser { isPin: json["isPin"] == null ? null : json["isPin"], isFav: json["isFav"] == null ? null : json["isFav"], isAdmin: json["isAdmin"] == null ? null : json["isAdmin"], + rKey: json["rKey"], + totalCount: json["totalCount"] == null ? null : json["totalCount"], isTyping: false, isImageLoaded: false, isImageLoading: true, @@ -80,7 +120,7 @@ class ChatUser { "userName": userName == null ? null : userName, "email": email == null ? null : email, "phone": phone, - "title": title, + "title": title == null ? null : title, "userStatus": userStatus == null ? null : userStatus, "image": image, "unreadMessageCount": unreadMessageCount == null ? null : unreadMessageCount, @@ -88,5 +128,7 @@ class ChatUser { "isPin": isPin == null ? null : isPin, "isFav": isFav == null ? null : isFav, "isAdmin": isAdmin == null ? null : isAdmin, + "rKey": rKey, + "totalCount": totalCount == null ? null : totalCount, }; } diff --git a/lib/provider/chat_provider_model.dart b/lib/provider/chat_provider_model.dart index f46b958..a809488 100644 --- a/lib/provider/chat_provider_model.dart +++ b/lib/provider/chat_provider_model.dart @@ -82,7 +82,6 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { } Future buildHubConnection() async { - chatHubConnection = await getHubConnection(); await chatHubConnection.start(); if (kDebugMode) { @@ -173,7 +172,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { if (isNewChat) { userChatHistory = []; } else if (loadMore) { - Utils.showToast("No More Data To Load"); + } } else { if (loadMore) { @@ -330,7 +329,15 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { user.userStatus = items.first["userStatus"]; } } - + if (teamMembersList != null) { + if (teamMembersList.isNotEmpty) { + for (ChatUser user in teamMembersList!) { + if (user.id == items.first["id"]) { + user.userStatus = items.first["userStatus"]; + } + } + } + } notifyListeners(); } diff --git a/lib/ui/chat/chat_home_screen.dart b/lib/ui/chat/chat_home_screen.dart index 395556a..aed4048 100644 --- a/lib/ui/chat/chat_home_screen.dart +++ b/lib/ui/chat/chat_home_screen.dart @@ -238,6 +238,7 @@ class _ChatHomeScreenState extends State { ), ), onPressed: () async { + print(AppState().chatDetails!.response!.token); showMyBottomSheet( context, callBackFunc: () {}, diff --git a/lib/widgets/bottom_sheets/search_employee_bottom_sheet.dart b/lib/widgets/bottom_sheets/search_employee_bottom_sheet.dart index 488b50f..014ce5d 100644 --- a/lib/widgets/bottom_sheets/search_employee_bottom_sheet.dart +++ b/lib/widgets/bottom_sheets/search_employee_bottom_sheet.dart @@ -24,6 +24,7 @@ import 'package:mohem_flutter_app/ui/chat/chat_detailed_screen.dart'; import 'package:mohem_flutter_app/widgets/button/default_button.dart'; import 'package:mohem_flutter_app/widgets/circular_avatar.dart'; import 'package:mohem_flutter_app/widgets/dynamic_forms/dynamic_textfield_widget.dart'; +import 'package:pull_to_refresh/pull_to_refresh.dart'; class SearchEmployeeBottomSheet extends StatefulWidget { int? notificationID; @@ -47,6 +48,8 @@ class SearchEmployeeBottomSheet extends StatefulWidget { class _SearchEmployeeBottomSheetState extends State { TextEditingController username = TextEditingController(); + ScrollController sc = ScrollController(); + String searchText = ""; List? optionsList = [ @@ -62,6 +65,7 @@ class _SearchEmployeeBottomSheetState extends State { // Chat Items List? chatUsersList = []; + int pageNo = 1; int _selectedSearchIndex = 0; @@ -88,12 +92,16 @@ class _SearchEmployeeBottomSheetState extends State { } void fetchChatUser({bool isNeedLoading = true}) async { + if (pageNo == 1) + chatUsersList = []; try { Utils.showLoading(context); - chatUsersList = await ChatApiClient().getChatMemberFromSearch( - searchText, - int.parse(AppState().chatDetails!.response!.id.toString()), - ); + await ChatApiClient().getChatMemberFromSearch(searchText, AppState().chatDetails!.response!.id!, pageNo).then((ChatUserModel value) { + print(value.response!.length); + if (value.response != null) { + chatUsersList = value.response; + } + }); chatUsersList!.removeWhere((ChatUser element) => element.id == AppState().chatDetails!.response!.id); Utils.hideLoading(context); setState(() {}); @@ -107,232 +115,263 @@ class _SearchEmployeeBottomSheetState extends State { return null; } - @override - Widget build(BuildContext context) { - return SizedBox( - width: double.infinity, - height: MediaQuery.of(context).size.height - 100, - child: Column( - children: [ - Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - widget.title.toText24(isBold: true), - 21.height, - "Search".toText16(), - 11.height, - Row( - children: [ - radioOption("Name", 0, _selectedSearchIndex), - radioOption("User Name", 1, _selectedSearchIndex), - radioOption("Email", 2, _selectedSearchIndex), - ], - ), - 14.height, - Row( - children: [ - DynamicTextFieldWidget( - "Search", - "Search By Username", - inputAction: TextInputAction.done, - suffixIconData: Icons.search, - onChange: (text) { - searchText = text; - setState(() {}); - }, - ).expanded, - IconButton( - constraints: const BoxConstraints(), - onPressed: () async { - await SystemChannels.textInput.invokeMethod('TextInput.hide'); - widget.fromChat ? fetchChatUser() : fetchUserByInput(); - }, - icon: const Icon(Icons.search), - ) - ], - ), - if (replacementList != null) - replacementList!.isEmpty - ? Utils.getNoDataWidget(context).expanded - : ListView( - physics: const BouncingScrollPhysics(), - padding: EdgeInsets.only(top: 21, bottom: 8), - children: [ - if (favouriteUserList?.isNotEmpty ?? false) ...[ - "Favorites".toText16(), - 12.height, - ListView.separated( - physics: const NeverScrollableScrollPhysics(), - shrinkWrap: true, - itemBuilder: (cxt, index) => employeeItemView(favouriteUserList![index]), - separatorBuilder: (cxt, index) => Container( - height: 1, - color: MyColors.borderE3Color, - ), - itemCount: favouriteUserList?.length ?? 0), - 12.height, - ], - if (nonFavouriteUserList?.isNotEmpty ?? false) ...[ - "Related".toText16(), - 12.height, - ListView.separated( - physics: const NeverScrollableScrollPhysics(), - shrinkWrap: true, - itemBuilder: (cxt, index) => employeeItemView(nonFavouriteUserList![index]), - separatorBuilder: (cxt, index) => Container( - height: 1, - color: MyColors.borderE3Color, - ), - itemCount: nonFavouriteUserList?.length ?? 0), - ] - ], - ).expanded, - if (widget.fromChat) - if (chatUsersList != null && widget.fromChat) - chatUsersList!.isEmpty - ? Column( - children: [ - 20.height, - Utils.getNoDataWidget(context), - ], - ) + void loadMoreChatUsers() async { + try { + await ChatApiClient().getChatMemberFromSearch(searchText, AppState().chatDetails!.response!.id!, pageNo).then((ChatUserModel value) { + if (value.response != null) { + chatUsersList!.addAll(value.response!); + } + }); + chatUsersList!.removeWhere((ChatUser element) => element.id == AppState().chatDetails!.response!.id); + } catch (e) { + Utils.hideLoading(context); + Utils.handleException(e, context, null); + } + } + + void scrollListener() async { + if (sc.position.pixels == + sc.position.maxScrollExtent) { + pageNo++; + setState(() {}); + } + + @override + void initState() { + super.initState(); + sc.addListener(scrollListener); + } + + @override + Widget build(BuildContext context) { + return SizedBox( + width: double.infinity, + height: MediaQuery + .of(context) + .size + .height - 100, + child: Column( + children: [ + Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + widget.title.toText24(isBold: true), + 21.height, + "Search".toText16(), + 11.height, + Row( + children: [ + radioOption("Name", 0, _selectedSearchIndex), + radioOption("User Name", 1, _selectedSearchIndex), + radioOption("Email", 2, _selectedSearchIndex), + ], + ), + 14.height, + Row( + children: [ + DynamicTextFieldWidget( + "Search", + "Search By Username", + inputAction: TextInputAction.done, + suffixIconData: Icons.search, + onChange: (text) { + searchText = text; + setState(() {}); + }, + ).expanded, + IconButton( + constraints: const BoxConstraints(), + onPressed: () async { + await SystemChannels.textInput.invokeMethod('TextInput.hide'); + widget.fromChat ? fetchChatUser() : fetchUserByInput(); + }, + icon: const Icon(Icons.search), + ) + ], + ), + if (replacementList != null) + replacementList!.isEmpty + ? Utils + .getNoDataWidget(context) + .expanded : ListView( - physics: const BouncingScrollPhysics(), - padding: const EdgeInsets.only( - top: 15, - ), - children: [ - ListView.separated( - physics: const NeverScrollableScrollPhysics(), - shrinkWrap: true, - itemBuilder: (BuildContext cxt, int index) { - return SizedBox( - height: 55, - child: ListTile( - leading: Stack( - children: [ - SvgPicture.asset( - "assets/images/user.svg", - height: 48, - width: 48, - ), - Positioned( - right: 5, - bottom: 1, - child: Container( - width: 10, - height: 10, - decoration: BoxDecoration( - color: chatUsersList![index].userStatus == 1 ? MyColors.green2DColor : Colors.red, - borderRadius: const BorderRadius.all( - Radius.circular(10), - ), - ), - ), - ) - ], + physics: const BouncingScrollPhysics(), + padding: EdgeInsets.only(top: 21, bottom: 8), + children: [ + if (favouriteUserList?.isNotEmpty ?? false) ...[ + "Favorites".toText16(), + 12.height, + ListView.separated( + physics: const NeverScrollableScrollPhysics(), + shrinkWrap: true, + itemBuilder: (cxt, index) => employeeItemView(favouriteUserList![index]), + separatorBuilder: (cxt, index) => + Container( + height: 1, + color: MyColors.borderE3Color, + ), + itemCount: favouriteUserList?.length ?? 0), + 12.height, + ], + if (nonFavouriteUserList?.isNotEmpty ?? false) ...[ + "Related".toText16(), + 12.height, + ListView.separated( + physics: const NeverScrollableScrollPhysics(), + shrinkWrap: true, + itemBuilder: (cxt, index) => employeeItemView(nonFavouriteUserList![index]), + separatorBuilder: (cxt, index) => + Container( + height: 1, + color: MyColors.borderE3Color, + ), + itemCount: nonFavouriteUserList?.length ?? 0), + ] + ], + ).expanded, + if (widget.fromChat) + if (chatUsersList != null && widget.fromChat) + chatUsersList!.isEmpty + ? Column( + children: [ + 20.height, + Utils.getNoDataWidget(context), + ], + ) + : ListView + .separated( + physics: const AlwaysScrollableScrollPhysics(), + controller: sc, + shrinkWrap: true, + itemBuilder: (BuildContext cxt, int index) { + return SizedBox( + height: 55, + child: ListTile( + leading: Stack( + children: [ + SvgPicture.asset( + "assets/images/user.svg", + height: 48, + width: 48, + ), + Positioned( + right: 5, + bottom: 1, + child: Container( + width: 10, + height: 10, + decoration: BoxDecoration( + color: chatUsersList![index].userStatus == 1 ? MyColors.green2DColor : Colors.red, + borderRadius: const BorderRadius.all( + Radius.circular(10), + ), ), - title: (chatUsersList![index].userName ?? "").toText14(color: MyColors.darkTextColor), - minVerticalPadding: 0, - onTap: () { - Navigator.pop(context); - Navigator.pushNamed( - context, - AppRoutes.chatDetailed, - arguments: ChatDetailedScreenParams(chatUsersList![index], true), - ); - }, ), - ); - }, - separatorBuilder: (BuildContext context, int index) => const Padding( - padding: EdgeInsets.only(right: 10, left: 70, bottom: 0, top: 0), - child: Divider( - color: Color(0xFFE5E5E5), - ), - ), - itemCount: chatUsersList?.length ?? 0, + ) + ], ), - 12.height, - ], - ).expanded, - ], - ).paddingOnly(left: 21, right: 21, bottom: 0, top: 21).expanded, - Container(width: double.infinity, height: 1, color: MyColors.lightGreyEFColor), - DefaultButton( - LocaleKeys.cancel.tr(), - () { - Navigator.pop(context); - }, - textColor: MyColors.grey3AColor, - colors: const [ - Color(0xffE6E6E6), - Color(0xffE6E6E6), - ], - ).insideContainer - ], - ), - ); - } - - Widget employeeItemView(ReplacementList replacement) { - return InkWell( - onTap: () { - Navigator.pop(context); - widget.onSelectEmployee(replacement); - }, - child: SizedBox( - height: 50, - child: Row( - children: [ - CircularAvatar( - url: replacement.employeeImage ?? "", - height: 30, - width: 30, - isImageBase64: true, - ), - 16.width, - Expanded( - child: (replacement.employeeDisplayName ?? "").toText12(), - ), - Icon(Icons.star, size: 16, color: replacement.isFavorite! ? MyColors.yellowFavColor : MyColors.borderCEColor), + title: (chatUsersList![index].userName ?? "").toText14(color: MyColors.darkTextColor), + minVerticalPadding: 0, + onTap: () { + Navigator.pop(context); + Navigator.pushNamed( + context, + AppRoutes.chatDetailed, + arguments: ChatDetailedScreenParams(chatUsersList![index], true), + ); + }, + ), + ); + }, + separatorBuilder: (BuildContext context, int index) => + const Padding( + padding: EdgeInsets.only(right: 10, left: 70, bottom: 0, top: 0), + child: Divider( + color: Color(0xFFE5E5E5), + ), + ), + itemCount: chatUsersList?.length ?? 0, + ) + .expanded, + ], + ) + .paddingOnly(left: 21, right: 21, bottom: 0, top: 21) + .expanded, + Container(width: double.infinity, height: 1, color: MyColors.lightGreyEFColor), + DefaultButton( + LocaleKeys.cancel.tr(), + () { + Navigator.pop(context); + }, + textColor: MyColors.grey3AColor, + colors: const [ + Color(0xffE6E6E6), + Color(0xffE6E6E6), + ], + ).insideContainer ], ), - ), - ); - } + ); + } - Widget radioOption(String title, int value, int groupValue) { - return Row( - children: [ - Container( - width: 24, - height: 24, - decoration: BoxDecoration( - color: Colors.transparent, - border: Border.all(color: MyColors.borderColor, width: 1), - borderRadius: const BorderRadius.all( - Radius.circular(100), - ), + Widget employeeItemView(ReplacementList replacement) { + return InkWell( + onTap: () { + Navigator.pop(context); + widget.onSelectEmployee(replacement); + }, + child: SizedBox( + height: 50, + child: Row( + children: [ + CircularAvatar( + url: replacement.employeeImage ?? "", + height: 30, + width: 30, + isImageBase64: true, + ), + 16.width, + Expanded( + child: (replacement.employeeDisplayName ?? "").toText12(), + ), + Icon(Icons.star, size: 16, color: replacement.isFavorite! ? MyColors.yellowFavColor : MyColors.borderCEColor), + ], ), - padding: const EdgeInsets.all(4), - child: Container( - width: double.infinity, - height: double.infinity, + ), + ); + } + + Widget radioOption(String title, int value, int groupValue) { + return Row( + children: [ + Container( + width: 24, + height: 24, decoration: BoxDecoration( - color: value == groupValue ? MyColors.grey3AColor : Colors.transparent, + color: Colors.transparent, + border: Border.all(color: MyColors.borderColor, width: 1), borderRadius: const BorderRadius.all( Radius.circular(100), ), ), + padding: const EdgeInsets.all(4), + child: Container( + width: double.infinity, + height: double.infinity, + decoration: BoxDecoration( + color: value == groupValue ? MyColors.grey3AColor : Colors.transparent, + borderRadius: const BorderRadius.all( + Radius.circular(100), + ), + ), + ), ), - ), - 9.width, - title.toText12(color: MyColors.grey57Color) - ], - ).onPress(() { - _selectedSearchIndex = value; - setState(() {}); - }).expanded; + 9.width, + title.toText12(color: MyColors.grey57Color) + ], + ).onPress(() { + _selectedSearchIndex = value; + setState(() {}); + }).expanded; + } } -} diff --git a/lib/widgets/shimmer/dashboard_shimmer_widget.dart b/lib/widgets/shimmer/dashboard_shimmer_widget.dart index d023898..c11cf16 100644 --- a/lib/widgets/shimmer/dashboard_shimmer_widget.dart +++ b/lib/widgets/shimmer/dashboard_shimmer_widget.dart @@ -273,7 +273,7 @@ class ChatHomeShimmer extends StatelessWidget { children: [ Container( width: double.infinity, - height: 8.0, + height: 20.0, color: Colors.white, ), const Padding( @@ -281,7 +281,7 @@ class ChatHomeShimmer extends StatelessWidget { ), Container( width: double.infinity, - height: 8.0, + height: 15.0, color: Colors.white, ), const Padding( @@ -289,7 +289,7 @@ class ChatHomeShimmer extends StatelessWidget { ), Container( width: 40.0, - height: 8.0, + height: 10.0, color: Colors.white, ), ], From d096559a2fa07998b4f7004b61b5ac1fee38d637 Mon Sep 17 00:00:00 2001 From: "Aamir.Muhammad" Date: Tue, 27 Dec 2022 14:30:16 +0300 Subject: [PATCH 3/4] Fixes --- .../search_employee_bottom_sheet.dart | 441 +++++++++--------- 1 file changed, 214 insertions(+), 227 deletions(-) diff --git a/lib/widgets/bottom_sheets/search_employee_bottom_sheet.dart b/lib/widgets/bottom_sheets/search_employee_bottom_sheet.dart index 014ce5d..a0041a7 100644 --- a/lib/widgets/bottom_sheets/search_employee_bottom_sheet.dart +++ b/lib/widgets/bottom_sheets/search_employee_bottom_sheet.dart @@ -92,8 +92,7 @@ class _SearchEmployeeBottomSheetState extends State { } void fetchChatUser({bool isNeedLoading = true}) async { - if (pageNo == 1) - chatUsersList = []; + if (pageNo == 1) chatUsersList!.clear(); try { Utils.showLoading(context); await ChatApiClient().getChatMemberFromSearch(searchText, AppState().chatDetails!.response!.id!, pageNo).then((ChatUserModel value) { @@ -130,248 +129,236 @@ class _SearchEmployeeBottomSheetState extends State { } void scrollListener() async { - if (sc.position.pixels == - sc.position.maxScrollExtent) { + if (sc.position.pixels == sc.position.maxScrollExtent) { pageNo++; setState(() {}); } + } - @override - void initState() { - super.initState(); - sc.addListener(scrollListener); - } + @override + void initState() { + super.initState(); + sc.addListener(scrollListener); + } - @override - Widget build(BuildContext context) { - return SizedBox( - width: double.infinity, - height: MediaQuery - .of(context) - .size - .height - 100, - child: Column( - children: [ - Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - widget.title.toText24(isBold: true), - 21.height, - "Search".toText16(), - 11.height, - Row( - children: [ - radioOption("Name", 0, _selectedSearchIndex), - radioOption("User Name", 1, _selectedSearchIndex), - radioOption("Email", 2, _selectedSearchIndex), - ], - ), - 14.height, - Row( - children: [ - DynamicTextFieldWidget( - "Search", - "Search By Username", - inputAction: TextInputAction.done, - suffixIconData: Icons.search, - onChange: (text) { - searchText = text; - setState(() {}); - }, - ).expanded, - IconButton( - constraints: const BoxConstraints(), - onPressed: () async { - await SystemChannels.textInput.invokeMethod('TextInput.hide'); - widget.fromChat ? fetchChatUser() : fetchUserByInput(); - }, - icon: const Icon(Icons.search), - ) - ], - ), - if (replacementList != null) - replacementList!.isEmpty - ? Utils - .getNoDataWidget(context) - .expanded - : ListView( - physics: const BouncingScrollPhysics(), - padding: EdgeInsets.only(top: 21, bottom: 8), - children: [ - if (favouriteUserList?.isNotEmpty ?? false) ...[ - "Favorites".toText16(), - 12.height, - ListView.separated( - physics: const NeverScrollableScrollPhysics(), - shrinkWrap: true, - itemBuilder: (cxt, index) => employeeItemView(favouriteUserList![index]), - separatorBuilder: (cxt, index) => - Container( - height: 1, - color: MyColors.borderE3Color, - ), - itemCount: favouriteUserList?.length ?? 0), - 12.height, - ], - if (nonFavouriteUserList?.isNotEmpty ?? false) ...[ - "Related".toText16(), - 12.height, - ListView.separated( - physics: const NeverScrollableScrollPhysics(), - shrinkWrap: true, - itemBuilder: (cxt, index) => employeeItemView(nonFavouriteUserList![index]), - separatorBuilder: (cxt, index) => - Container( - height: 1, - color: MyColors.borderE3Color, - ), - itemCount: nonFavouriteUserList?.length ?? 0), - ] - ], + @override + Widget build(BuildContext context) { + return SizedBox( + width: double.infinity, + height: MediaQuery.of(context).size.height - 100, + child: Column( + children: [ + Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + widget.title.toText24(isBold: true), + 21.height, + "Search".toText16(), + 11.height, + Row( + children: [ + radioOption("Name", 0, _selectedSearchIndex), + radioOption("User Name", 1, _selectedSearchIndex), + radioOption("Email", 2, _selectedSearchIndex), + ], + ), + 14.height, + Row( + children: [ + DynamicTextFieldWidget( + "Search", + "Search By Username", + inputAction: TextInputAction.done, + suffixIconData: Icons.search, + onChange: (text) { + searchText = text; + setState(() {}); + }, ).expanded, - if (widget.fromChat) - if (chatUsersList != null && widget.fromChat) - chatUsersList!.isEmpty - ? Column( - children: [ - 20.height, - Utils.getNoDataWidget(context), - ], - ) - : ListView - .separated( - physics: const AlwaysScrollableScrollPhysics(), - controller: sc, - shrinkWrap: true, - itemBuilder: (BuildContext cxt, int index) { - return SizedBox( - height: 55, - child: ListTile( - leading: Stack( - children: [ - SvgPicture.asset( - "assets/images/user.svg", - height: 48, - width: 48, - ), - Positioned( - right: 5, - bottom: 1, - child: Container( - width: 10, - height: 10, - decoration: BoxDecoration( - color: chatUsersList![index].userStatus == 1 ? MyColors.green2DColor : Colors.red, - borderRadius: const BorderRadius.all( - Radius.circular(10), - ), + IconButton( + constraints: const BoxConstraints(), + onPressed: () async { + await SystemChannels.textInput.invokeMethod('TextInput.hide'); + widget.fromChat ? fetchChatUser() : fetchUserByInput(); + }, + icon: const Icon(Icons.search), + ) + ], + ), + if (replacementList != null) + replacementList!.isEmpty + ? Utils.getNoDataWidget(context).expanded + : ListView( + physics: const BouncingScrollPhysics(), + padding: EdgeInsets.only(top: 21, bottom: 8), + children: [ + if (favouriteUserList?.isNotEmpty ?? false) ...[ + "Favorites".toText16(), + 12.height, + ListView.separated( + physics: const NeverScrollableScrollPhysics(), + shrinkWrap: true, + itemBuilder: (cxt, index) => employeeItemView(favouriteUserList![index]), + separatorBuilder: (cxt, index) => Container( + height: 1, + color: MyColors.borderE3Color, + ), + itemCount: favouriteUserList?.length ?? 0), + 12.height, + ], + if (nonFavouriteUserList?.isNotEmpty ?? false) ...[ + "Related".toText16(), + 12.height, + ListView.separated( + physics: const NeverScrollableScrollPhysics(), + shrinkWrap: true, + itemBuilder: (cxt, index) => employeeItemView(nonFavouriteUserList![index]), + separatorBuilder: (cxt, index) => Container( + height: 1, + color: MyColors.borderE3Color, ), - ), - ) - ], + itemCount: nonFavouriteUserList?.length ?? 0), + ] + ], + ).expanded, + if (widget.fromChat) + if (chatUsersList != null && widget.fromChat) + chatUsersList!.isEmpty + ? Column( + children: [ + 20.height, + Utils.getNoDataWidget(context), + ], + ) + : ListView.separated( + physics: const AlwaysScrollableScrollPhysics(), + controller: sc, + shrinkWrap: true, + itemBuilder: (BuildContext cxt, int index) { + return SizedBox( + height: 55, + child: ListTile( + leading: Stack( + children: [ + SvgPicture.asset( + "assets/images/user.svg", + height: 48, + width: 48, + ), + Positioned( + right: 5, + bottom: 1, + child: Container( + width: 10, + height: 10, + decoration: BoxDecoration( + color: chatUsersList![index].userStatus == 1 ? MyColors.green2DColor : Colors.red, + borderRadius: const BorderRadius.all( + Radius.circular(10), + ), + ), + ), + ) + ], + ), + title: (chatUsersList![index].userName ?? "").toText14(color: MyColors.darkTextColor), + minVerticalPadding: 0, + onTap: () { + Navigator.pop(context); + Navigator.pushNamed( + context, + AppRoutes.chatDetailed, + arguments: ChatDetailedScreenParams(chatUsersList![index], true), + ); + }, + ), + ); + }, + separatorBuilder: (BuildContext context, int index) => const Padding( + padding: EdgeInsets.only(right: 10, left: 70, bottom: 0, top: 0), + child: Divider( + color: Color(0xFFE5E5E5), ), - title: (chatUsersList![index].userName ?? "").toText14(color: MyColors.darkTextColor), - minVerticalPadding: 0, - onTap: () { - Navigator.pop(context); - Navigator.pushNamed( - context, - AppRoutes.chatDetailed, - arguments: ChatDetailedScreenParams(chatUsersList![index], true), - ); - }, ), - ); - }, - separatorBuilder: (BuildContext context, int index) => - const Padding( - padding: EdgeInsets.only(right: 10, left: 70, bottom: 0, top: 0), - child: Divider( - color: Color(0xFFE5E5E5), - ), - ), - itemCount: chatUsersList?.length ?? 0, - ) - .expanded, - ], - ) - .paddingOnly(left: 21, right: 21, bottom: 0, top: 21) - .expanded, - Container(width: double.infinity, height: 1, color: MyColors.lightGreyEFColor), - DefaultButton( - LocaleKeys.cancel.tr(), - () { - Navigator.pop(context); - }, - textColor: MyColors.grey3AColor, - colors: const [ - Color(0xffE6E6E6), - Color(0xffE6E6E6), - ], - ).insideContainer + itemCount: chatUsersList?.length ?? 0, + ).expanded, + ], + ).paddingOnly(left: 21, right: 21, bottom: 0, top: 21).expanded, + Container(width: double.infinity, height: 1, color: MyColors.lightGreyEFColor), + DefaultButton( + LocaleKeys.cancel.tr(), + () { + Navigator.pop(context); + }, + textColor: MyColors.grey3AColor, + colors: const [ + Color(0xffE6E6E6), + Color(0xffE6E6E6), + ], + ).insideContainer + ], + ), + ); + } + + Widget employeeItemView(ReplacementList replacement) { + return InkWell( + onTap: () { + Navigator.pop(context); + widget.onSelectEmployee(replacement); + }, + child: SizedBox( + height: 50, + child: Row( + children: [ + CircularAvatar( + url: replacement.employeeImage ?? "", + height: 30, + width: 30, + isImageBase64: true, + ), + 16.width, + Expanded( + child: (replacement.employeeDisplayName ?? "").toText12(), + ), + Icon(Icons.star, size: 16, color: replacement.isFavorite! ? MyColors.yellowFavColor : MyColors.borderCEColor), ], ), - ); - } + ), + ); + } - Widget employeeItemView(ReplacementList replacement) { - return InkWell( - onTap: () { - Navigator.pop(context); - widget.onSelectEmployee(replacement); - }, - child: SizedBox( - height: 50, - child: Row( - children: [ - CircularAvatar( - url: replacement.employeeImage ?? "", - height: 30, - width: 30, - isImageBase64: true, - ), - 16.width, - Expanded( - child: (replacement.employeeDisplayName ?? "").toText12(), - ), - Icon(Icons.star, size: 16, color: replacement.isFavorite! ? MyColors.yellowFavColor : MyColors.borderCEColor), - ], + Widget radioOption(String title, int value, int groupValue) { + return Row( + children: [ + Container( + width: 24, + height: 24, + decoration: BoxDecoration( + color: Colors.transparent, + border: Border.all(color: MyColors.borderColor, width: 1), + borderRadius: const BorderRadius.all( + Radius.circular(100), + ), ), - ), - ); - } - - Widget radioOption(String title, int value, int groupValue) { - return Row( - children: [ - Container( - width: 24, - height: 24, + padding: const EdgeInsets.all(4), + child: Container( + width: double.infinity, + height: double.infinity, decoration: BoxDecoration( - color: Colors.transparent, - border: Border.all(color: MyColors.borderColor, width: 1), + color: value == groupValue ? MyColors.grey3AColor : Colors.transparent, borderRadius: const BorderRadius.all( Radius.circular(100), ), ), - padding: const EdgeInsets.all(4), - child: Container( - width: double.infinity, - height: double.infinity, - decoration: BoxDecoration( - color: value == groupValue ? MyColors.grey3AColor : Colors.transparent, - borderRadius: const BorderRadius.all( - Radius.circular(100), - ), - ), - ), ), - 9.width, - title.toText12(color: MyColors.grey57Color) - ], - ).onPress(() { - _selectedSearchIndex = value; - setState(() {}); - }).expanded; - } + ), + 9.width, + title.toText12(color: MyColors.grey57Color) + ], + ).onPress(() { + _selectedSearchIndex = value; + setState(() {}); + }).expanded; } +} From a746b607dfda805c461750b371591a57d425e6e7 Mon Sep 17 00:00:00 2001 From: "Aamir.Muhammad" Date: Tue, 27 Dec 2022 16:21:25 +0300 Subject: [PATCH 4/4] Fixes --- lib/classes/consts.dart | 5 +- .../chat/get_search_user_chat_model.dart | 1 - lib/provider/chat_provider_model.dart | 40 +++- .../search_employee_bottom_sheet.dart | 213 ++++++++++++------ 4 files changed, 183 insertions(+), 76 deletions(-) diff --git a/lib/classes/consts.dart b/lib/classes/consts.dart index 990656f..a2af129 100644 --- a/lib/classes/consts.dart +++ b/lib/classes/consts.dart @@ -3,8 +3,8 @@ import 'package:mohem_flutter_app/ui/marathon/widgets/question_card.dart'; class ApiConsts { //static String baseUrl = "http://10.200.204.20:2801/"; // Local server // static String baseUrl = "https://erptstapp.srca.org.sa"; // SRCA server - // static String baseUrl = "https://uat.hmgwebservices.com"; // UAT server - static String baseUrl = "https://hmgwebservices.com"; // Live server + //static String baseUrl = "https://uat.hmgwebservices.com"; // UAT server + static String baseUrl = "https://hmgwebservices.com"; // Live server static String baseUrlServices = baseUrl + "/Services/"; // server // static String baseUrlServices = "https://api.cssynapses.com/tangheem/"; // Live server static String utilitiesRest = baseUrlServices + "Utilities.svc/REST/"; @@ -44,7 +44,6 @@ class ApiConsts { static int tabletMinLength = 500; } - class SharedPrefsConsts { static String isRememberMe = "remember_me"; static String username = "username"; diff --git a/lib/models/chat/get_search_user_chat_model.dart b/lib/models/chat/get_search_user_chat_model.dart index e1c87a3..e69fd3b 100644 --- a/lib/models/chat/get_search_user_chat_model.dart +++ b/lib/models/chat/get_search_user_chat_model.dart @@ -1,4 +1,3 @@ - import 'dart:convert'; import 'dart:io'; diff --git a/lib/provider/chat_provider_model.dart b/lib/provider/chat_provider_model.dart index 76a47c2..b4bd451 100644 --- a/lib/provider/chat_provider_model.dart +++ b/lib/provider/chat_provider_model.dart @@ -69,6 +69,10 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { //Chat Home Page Counter int chatUConvCounter = 0; + /// Search Provider + List? chatUsersList = []; + int pageNo = 1; + Future getUserAutoLoginToken() async { userLoginToken.UserAutoLoginModel userLoginResponse = await ChatApiClient().getUserLoginToken(); if (userLoginResponse.response != null) { @@ -82,7 +86,6 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { } Future buildHubConnection() async { - chatHubConnection = await getHubConnection(); await chatHubConnection.start(); if (kDebugMode) { @@ -173,7 +176,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { if (isNewChat) { userChatHistory = []; } else if (loadMore) { - Utils.showToast("No More Data To Load"); + } } else { if (loadMore) { @@ -942,8 +945,26 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { } } } + + for (ChatUser user in chatUsersList!) { + if (user.id == favoriteChatUser.response!.targetUserId!) { + user.isFav = favoriteChatUser.response!.isFav; + dynamic contain = favUsersList!.where((ChatUser element) => element.id == favoriteChatUser.response!.targetUserId!); + if (contain.isEmpty) { + favUsersList.add(user); + } + } + } + } + for (ChatUser user in favUsersList) { + if (user.id == targetUserID) { + user.userLocalDownlaodedImage = null; + user.isImageLoading = false; + user.isImageLoaded = false; + } } notifyListeners(); + } Future unFavoriteUser({required int userID, required int targetUserID}) async { @@ -960,6 +981,12 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { ); } + for (ChatUser user in chatUsersList!) { + if (user.id == favoriteChatUser.response!.targetUserId!) { + user.isFav = favoriteChatUser.response!.isFav; + } + } + notifyListeners(); } @@ -1348,6 +1375,15 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { } } } + + for (ChatUser user in searchedChats!) { + for (ChatUser teamUser in teamMembersList!) { + if (user.id == teamUser.id) { + teamUser.userStatus = user.userStatus; + } + } + } + isLoading = false; notifyListeners(); } diff --git a/lib/widgets/bottom_sheets/search_employee_bottom_sheet.dart b/lib/widgets/bottom_sheets/search_employee_bottom_sheet.dart index a0041a7..eada55f 100644 --- a/lib/widgets/bottom_sheets/search_employee_bottom_sheet.dart +++ b/lib/widgets/bottom_sheets/search_employee_bottom_sheet.dart @@ -20,10 +20,12 @@ import 'package:mohem_flutter_app/models/chat/get_search_user_chat_model.dart'; import 'package:mohem_flutter_app/models/get_action_history_list_model.dart'; import 'package:mohem_flutter_app/models/worklist/get_favorite_replacements_model.dart'; import 'package:mohem_flutter_app/models/worklist/replacement_list_model.dart'; +import 'package:mohem_flutter_app/provider/chat_provider_model.dart'; import 'package:mohem_flutter_app/ui/chat/chat_detailed_screen.dart'; import 'package:mohem_flutter_app/widgets/button/default_button.dart'; import 'package:mohem_flutter_app/widgets/circular_avatar.dart'; import 'package:mohem_flutter_app/widgets/dynamic_forms/dynamic_textfield_widget.dart'; +import 'package:provider/provider.dart'; import 'package:pull_to_refresh/pull_to_refresh.dart'; class SearchEmployeeBottomSheet extends StatefulWidget { @@ -64,8 +66,7 @@ class _SearchEmployeeBottomSheetState extends State { List? nonFavouriteUserList; // Chat Items - List? chatUsersList = []; - int pageNo = 1; + late ChatProviderModel provider; int _selectedSearchIndex = 0; @@ -92,46 +93,37 @@ class _SearchEmployeeBottomSheetState extends State { } void fetchChatUser({bool isNeedLoading = true}) async { - if (pageNo == 1) chatUsersList!.clear(); + if (provider.pageNo == 1) provider.chatUsersList!.clear(); try { Utils.showLoading(context); - await ChatApiClient().getChatMemberFromSearch(searchText, AppState().chatDetails!.response!.id!, pageNo).then((ChatUserModel value) { - print(value.response!.length); + await ChatApiClient().getChatMemberFromSearch(searchText, AppState().chatDetails!.response!.id!, provider.pageNo).then((ChatUserModel value) { if (value.response != null) { - chatUsersList = value.response; + if (provider.pageNo == 1) { + provider.chatUsersList = value.response; + } else { + print("--------------------------Added More----------------------"); + provider.chatUsersList!.addAll(value.response!); + } } }); - chatUsersList!.removeWhere((ChatUser element) => element.id == AppState().chatDetails!.response!.id); + provider.chatUsersList!.removeWhere((ChatUser element) => element.id == AppState().chatDetails!.response!.id); Utils.hideLoading(context); setState(() {}); } catch (e) { Utils.hideLoading(context); Utils.handleException(e, context, null); } - if (isNeedLoading) Utils.hideLoading(context); setState(() {}); return null; } - void loadMoreChatUsers() async { - try { - await ChatApiClient().getChatMemberFromSearch(searchText, AppState().chatDetails!.response!.id!, pageNo).then((ChatUserModel value) { - if (value.response != null) { - chatUsersList!.addAll(value.response!); - } - }); - chatUsersList!.removeWhere((ChatUser element) => element.id == AppState().chatDetails!.response!.id); - } catch (e) { - Utils.hideLoading(context); - Utils.handleException(e, context, null); - } - } - void scrollListener() async { if (sc.position.pixels == sc.position.maxScrollExtent) { - pageNo++; - setState(() {}); + provider.pageNo++; + logger.w(provider.chatUsersList!.length); + logger.w(provider.pageNo); + fetchChatUser(); } } @@ -139,6 +131,15 @@ class _SearchEmployeeBottomSheetState extends State { void initState() { super.initState(); sc.addListener(scrollListener); + provider = Provider.of(context, listen: false); + } + + @override + void dispose() { + print("// TODO: implement dispose"); + super.dispose(); + provider.chatUsersList = []; + provider.pageNo = 1; } @override @@ -157,7 +158,7 @@ class _SearchEmployeeBottomSheetState extends State { 11.height, Row( children: [ - radioOption("Name", 0, _selectedSearchIndex), + radioOption(widget.fromChat ? "UserId" : "Name", 0, _selectedSearchIndex), radioOption("User Name", 1, _selectedSearchIndex), radioOption("Email", 2, _selectedSearchIndex), ], @@ -222,8 +223,8 @@ class _SearchEmployeeBottomSheetState extends State { ], ).expanded, if (widget.fromChat) - if (chatUsersList != null && widget.fromChat) - chatUsersList!.isEmpty + if (provider.chatUsersList != null && widget.fromChat) + provider.chatUsersList!.isEmpty ? Column( children: [ 20.height, @@ -231,56 +232,126 @@ class _SearchEmployeeBottomSheetState extends State { ], ) : ListView.separated( - physics: const AlwaysScrollableScrollPhysics(), - controller: sc, + itemCount: provider.chatUsersList!.length, shrinkWrap: true, - itemBuilder: (BuildContext cxt, int index) { + physics: const ClampingScrollPhysics(), + controller: sc, + padding: const EdgeInsets.only(bottom: 80.0, top: 20), + itemBuilder: (BuildContext context, int index) { return SizedBox( height: 55, - child: ListTile( - leading: Stack( - children: [ + child: Row( + children: [ + Stack( + children: [ SvgPicture.asset( - "assets/images/user.svg", - height: 48, - width: 48, - ), - Positioned( - right: 5, - bottom: 1, - child: Container( - width: 10, - height: 10, - decoration: BoxDecoration( - color: chatUsersList![index].userStatus == 1 ? MyColors.green2DColor : Colors.red, - borderRadius: const BorderRadius.all( - Radius.circular(10), - ), + "assets/images/user.svg", + height: 48, + width: 48, ), - ), - ) - ], - ), - title: (chatUsersList![index].userName ?? "").toText14(color: MyColors.darkTextColor), - minVerticalPadding: 0, - onTap: () { - Navigator.pop(context); - Navigator.pushNamed( - context, - AppRoutes.chatDetailed, - arguments: ChatDetailedScreenParams(chatUsersList![index], true), - ); - }, + Positioned( + right: 5, + bottom: 1, + child: Container( + width: 10, + height: 10, + decoration: BoxDecoration( + color: provider.chatUsersList![index].userStatus == 1 ? MyColors.green2DColor : Colors.red, + ), + ).circle(10), + ) + ], + ), + Column( + mainAxisAlignment: MainAxisAlignment.start, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + (provider.chatUsersList![index].userName!.replaceFirst(".", " ").capitalizeFirstofEach ?? "") + .toText14(color: MyColors.darkTextColor) + .paddingOnly(left: 11, top: 13), + provider.chatUsersList![index].isTyping! + ? 'Typing...' + .toText10( + color: MyColors.textMixColor, + ) + .paddingOnly(left: 11.0) + : const SizedBox() + ], + ).expanded, + SizedBox( + width: 60, + child: Row( + crossAxisAlignment: CrossAxisAlignment.center, + mainAxisAlignment: MainAxisAlignment.end, + mainAxisSize: MainAxisSize.max, + children: [ + if (provider.chatUsersList![index].unreadMessageCount! > 0) + Container( + alignment: Alignment.center, + width: 18, + height: 18, + decoration: const BoxDecoration( + color: MyColors.redColor, + borderRadius: BorderRadius.all( + Radius.circular(20), + ), + ), + child: (provider.chatUsersList![index].unreadMessageCount!.toString()) + .toText10( + color: MyColors.white, + ) + .center, + ).paddingOnly(right: 10).center, + Icon( + provider.chatUsersList![index].isFav != null && provider.chatUsersList![index].isFav == false ? Icons.star_sharp : Icons.star_sharp, + color: provider.chatUsersList![index].isFav != null && provider.chatUsersList![index].isFav == true ? MyColors.yellowColor : MyColors.grey35Color, + ).onPress( + () { + if (provider.chatUsersList![index].isFav == null || provider.chatUsersList![index].isFav == false) { + provider + .favoriteUser( + userID: AppState().chatDetails!.response!.id!, + targetUserID: provider.chatUsersList![index].id!, + ) + .then((value) { + setState(() {}); + }); + } else if (provider.chatUsersList![index].isFav == true) { + provider + .unFavoriteUser( + userID: AppState().chatDetails!.response!.id!, + targetUserID: provider.chatUsersList![index].id!, + ) + .then((value) { + setState(() {}); + }); + } else { + provider + .favoriteUser( + userID: AppState().chatDetails!.response!.id!, + targetUserID: provider.chatUsersList![index].id!, + ) + .then((value) { + setState(() {}); + }); + } + }, + ).center + ], + ), + ), + ], ), - ); + ).onPress(() { + Navigator.pop(context); + Navigator.pushNamed( + context, + AppRoutes.chatDetailed, + arguments: ChatDetailedScreenParams(provider.chatUsersList![index], true), + ); + }); }, - separatorBuilder: (BuildContext context, int index) => const Padding( - padding: EdgeInsets.only(right: 10, left: 70, bottom: 0, top: 0), - child: Divider( - color: Color(0xFFE5E5E5), - ), - ), - itemCount: chatUsersList?.length ?? 0, + separatorBuilder: (BuildContext context, int index) => const Divider(color: MyColors.lightGreyE5Color).paddingOnly(left: 59), ).expanded, ], ).paddingOnly(left: 21, right: 21, bottom: 0, top: 21).expanded, @@ -289,6 +360,8 @@ class _SearchEmployeeBottomSheetState extends State { LocaleKeys.cancel.tr(), () { Navigator.pop(context); + provider.chatUsersList = []; + provider.pageNo = 1; }, textColor: MyColors.grey3AColor, colors: const [