From d4b31d4338c520cf89807592ac72a0aa59f7e89f Mon Sep 17 00:00:00 2001 From: "Aamir.Muhammad" Date: Wed, 19 Oct 2022 09:54:44 +0300 Subject: [PATCH 1/6] Chat Login Api Implementation --- lib/api/chat/chat_provider_model.dart | 28 ++- .../attendance/add_vacation_rule_screen.dart | 1 + lib/ui/chat/chat_home.dart | 1 + .../add_leave_balance_screen.dart | 1 + .../search_employee_bottom_sheet.dart | 206 ++++++++++++------ 5 files changed, 165 insertions(+), 72 deletions(-) diff --git a/lib/api/chat/chat_provider_model.dart b/lib/api/chat/chat_provider_model.dart index 465c5af..fe95696 100644 --- a/lib/api/chat/chat_provider_model.dart +++ b/lib/api/chat/chat_provider_model.dart @@ -35,17 +35,19 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { await buildHubConnection(); } - void getChatMemberFromSearch(String sName, int cUserId) async { - isLoading = true; - notifyListeners(); + Future?> getChatMemberFromSearch(String sName, int cUserId) async { Response response = await ApiClient().getJsonForResponse( - "${ApiConsts.chatSearchMember}$sName/$cUserId", + "${ApiConsts.chatServerBaseApiUrl}${ApiConsts.chatSearchMember}$sName/$cUserId", token: AppState().chatDetails!.response!.token, ); + return searchUserJsonModel(response.body); + logger.d(response.body); isLoading = false; notifyListeners(); } + List searchUserJsonModel(String str) => List.from(json.decode(str).map((x) => ChatUser.fromJson(x))); + void getUserRecentChats() async { Response response = await ApiClient().getJsonForResponse( "${ApiConsts.chatServerBaseApiUrl}${ApiConsts.chatRecentUrl}", @@ -64,8 +66,14 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { "${ApiConsts.chatServerBaseApiUrl}${ApiConsts.chatSingleUserHistoryUrl}/$senderUID/$receiverUID/$pagination", token: AppState().chatDetails!.response!.token, ); - logger.d(response.body); - userChatHistory = getSingleUserChatintoModel(response.body); + logger.d(response.statusCode); + print(response.body); + if (response.statusCode == 204) { + print(null); + userChatHistory = []; + } else { + userChatHistory = getSingleUserChatintoModel(response.body); + } isLoading = false; notifyListeners(); } @@ -79,7 +87,9 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { hubConnection = await HubConnectionBuilder() .withUrl(ApiConsts.chatHubConnectionUrl + "?UserId=${AppState().chatDetails!.response!.id}&source=Web&access_token=${AppState().chatDetails!.response!.token}", options: httpOp) .withAutomaticReconnect(retryDelays: [2000, 5000, 10000, 20000]) - .configureLogging(Logger("Logs Enabled")) + .configureLogging( + Logger("Logs Enabled"), + ) .build(); hubConnection.onclose( ({Exception? error}) { @@ -159,7 +169,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { // print("================= Status Online // Offline ===================="); List items = args!.toList(); logger.d(items); - for (var user in searchedChats!) { + for (ChatUser user in searchedChats!) { if (user.id == items.first["id"]) { user.userStatus = items.first["userStatus"]; } @@ -172,7 +182,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { if (value.isEmpty || value == "") { tmp = pChatHistory; } else { - for (var element in pChatHistory!) { + for (ChatUser element in pChatHistory!) { if (element.userName!.toLowerCase().contains(value.toLowerCase())) { tmp.add(element); } diff --git a/lib/ui/attendance/add_vacation_rule_screen.dart b/lib/ui/attendance/add_vacation_rule_screen.dart index 4846053..aa48696 100644 --- a/lib/ui/attendance/add_vacation_rule_screen.dart +++ b/lib/ui/attendance/add_vacation_rule_screen.dart @@ -433,6 +433,7 @@ class _AddVacationRuleScreenState extends State { child: SearchEmployeeBottomSheet( title: LocaleKeys.searchForEmployee.tr(), apiMode: LocaleKeys.delegate.tr(), + fromChat: false, onSelectEmployee: (_selectedEmployee) { // Navigator.pop(context); selectedReplacementEmployee = _selectedEmployee; diff --git a/lib/ui/chat/chat_home.dart b/lib/ui/chat/chat_home.dart index 18c11bf..ef984a3 100644 --- a/lib/ui/chat/chat_home.dart +++ b/lib/ui/chat/chat_home.dart @@ -163,6 +163,7 @@ class _ChatHomeScreenState extends State { child: SearchEmployeeBottomSheet( title: LocaleKeys.searchForEmployee.tr(), apiMode: LocaleKeys.delegate.tr(), + fromChat: true, onSelectEmployee: (_selectedEmployee) { // Navigator.pop(context); // selectedReplacementEmployee = _selectedEmployee; diff --git a/lib/ui/leave_balance/add_leave_balance_screen.dart b/lib/ui/leave_balance/add_leave_balance_screen.dart index eb8e493..81cfe0f 100644 --- a/lib/ui/leave_balance/add_leave_balance_screen.dart +++ b/lib/ui/leave_balance/add_leave_balance_screen.dart @@ -224,6 +224,7 @@ class _AddLeaveBalanceScreenState extends State { child: SearchEmployeeBottomSheet( title: LocaleKeys.searchForEmployee.tr(), apiMode: LocaleKeys.delegate.tr(), + fromChat: false, onSelectEmployee: (_selectedEmployee) { // Navigator.pop(context); selectedReplacementEmployee = _selectedEmployee; diff --git a/lib/widgets/bottom_sheets/search_employee_bottom_sheet.dart b/lib/widgets/bottom_sheets/search_employee_bottom_sheet.dart index e807a7b..14da765 100644 --- a/lib/widgets/bottom_sheets/search_employee_bottom_sheet.dart +++ b/lib/widgets/bottom_sheets/search_employee_bottom_sheet.dart @@ -1,14 +1,21 @@ +import 'dart:convert'; + import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; +import 'package:flutter_svg/flutter_svg.dart'; +import 'package:mohem_flutter_app/api/chat/chat_provider_model.dart'; import 'package:mohem_flutter_app/api/worklist/worklist_api_client.dart'; +import 'package:mohem_flutter_app/app_state/app_state.dart'; import 'package:mohem_flutter_app/classes/colors.dart'; import 'package:mohem_flutter_app/classes/utils.dart'; +import 'package:mohem_flutter_app/config/routes.dart'; import 'package:mohem_flutter_app/extensions/int_extensions.dart'; import 'package:mohem_flutter_app/extensions/string_extensions.dart'; import 'package:mohem_flutter_app/extensions/widget_extensions.dart'; import 'package:mohem_flutter_app/generated/locale_keys.g.dart'; +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'; @@ -21,17 +28,19 @@ class SearchEmployeeBottomSheet extends StatefulWidget { String title, apiMode; List? actionHistoryList; Function(ReplacementList) onSelectEmployee; + bool fromChat; - SearchEmployeeBottomSheet( - {required this.title, - required this.apiMode, - this.notificationID, - this.actionHistoryList, - required this.onSelectEmployee}); + SearchEmployeeBottomSheet({ + required this.title, + required this.apiMode, + this.notificationID, + this.actionHistoryList, + required this.onSelectEmployee, + required this.fromChat, + }); @override - State createState() => - _SearchEmployeeBottomSheetState(); + State createState() => _SearchEmployeeBottomSheetState(); } class _SearchEmployeeBottomSheetState extends State { @@ -49,6 +58,9 @@ class _SearchEmployeeBottomSheetState extends State { List? favouriteUserList; List? nonFavouriteUserList; + // Chat Items + List? chatUsersList = []; + int _selectedSearchIndex = 0; void fetchUserByInput({bool isNeedLoading = true}) async { @@ -59,12 +71,30 @@ class _SearchEmployeeBottomSheetState extends State { userId: _selectedSearchIndex == 1 ? searchText : "", email: _selectedSearchIndex == 2 ? searchText : "", ); - favouriteUserList = replacementList - ?.where((element) => element.isFavorite ?? false) - .toList(); - nonFavouriteUserList = replacementList - ?.where((element) => !(element.isFavorite ?? false)) - .toList(); + favouriteUserList = replacementList?.where((element) => element.isFavorite ?? false).toList(); + nonFavouriteUserList = replacementList?.where((element) => !(element.isFavorite ?? false)).toList(); + Utils.hideLoading(context); + setState(() {}); + } catch (e) { + Utils.hideLoading(context); + Utils.handleException(e, context, null); + } + + if (isNeedLoading) Utils.hideLoading(context); + setState(() {}); + return null; + } + + void fetchChatUser({bool isNeedLoading = true}) async { + try { + Utils.showLoading(context); + + chatUsersList = await ChatProviderModel().getChatMemberFromSearch(searchText, int.parse(AppState().chatDetails!.response!.id.toString())); + print("================================"); + print(jsonEncode(chatUsersList)); + // + // favouriteUserList = replacementList?.where((element) => element.isFavorite ?? false).toList(); + // nonFavouriteUserList = replacementList?.where((element) => !(element.isFavorite ?? false)).toList(); Utils.hideLoading(context); setState(() {}); } catch (e) { @@ -114,57 +144,113 @@ class _SearchEmployeeBottomSheetState extends State { IconButton( constraints: const BoxConstraints(), onPressed: () async { - await SystemChannels.textInput - .invokeMethod('TextInput.hide'); - fetchUserByInput(); + await SystemChannels.textInput.invokeMethod('TextInput.hide'); + widget.fromChat ? fetchChatUser() : fetchUserByInput(); }, icon: 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, + : 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 + ? Utils.getNoDataWidget(context) + : ListView( + physics: const BouncingScrollPhysics(), + padding: EdgeInsets.only(top: 0, bottom: 8), + children: [ + ListView.separated( + physics: const NeverScrollableScrollPhysics(), + shrinkWrap: true, + + itemBuilder: (cxt, index) { + return 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), + ), + ), ), - itemCount: nonFavouriteUserList?.length ?? 0), - ] - ], - ).expanded + ) + ], + ), + title: (chatUsersList![index].userName ?? "").toText14(color: MyColors.darkTextColor), + subtitle: (chatUsersList![index].isTyping == true ? "Something is Typing" : "Last message text").toText11(color: MyColors.normalTextColor), + trailing: ("Today").toText10(color: MyColors.lightTextColor), + minVerticalPadding: 0, + onTap: () { + Navigator.pop(context); + Navigator.pushNamed( + context, + AppRoutes.chatDetailed, + arguments: {"targetUser": chatUsersList![index]}, + ); + }, + ); + }, + separatorBuilder: (cxt, index) => Container( + height: 1, + color: MyColors.borderE3Color, + ), + 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), + + Container(width: double.infinity, height: 1, color: MyColors.lightGreyEFColor), DefaultButton( LocaleKeys.cancel.tr(), () { @@ -201,11 +287,7 @@ class _SearchEmployeeBottomSheetState extends State { Expanded( child: (replacement.employeeDisplayName ?? "").toText12(), ), - Icon(Icons.star, - size: 16, - color: replacement.isFavorite! - ? MyColors.yellowFavColor - : MyColors.borderCEColor), + Icon(Icons.star, size: 16, color: replacement.isFavorite! ? MyColors.yellowFavColor : MyColors.borderCEColor), ], ), ), @@ -228,9 +310,7 @@ class _SearchEmployeeBottomSheetState extends State { width: double.infinity, height: double.infinity, decoration: BoxDecoration( - color: value == groupValue - ? MyColors.grey3AColor - : Colors.transparent, + color: value == groupValue ? MyColors.grey3AColor : Colors.transparent, borderRadius: BorderRadius.all(const Radius.circular(100)), ), ), From 05c6cc7f140a270b0b22c7ec848afa8a0370959b Mon Sep 17 00:00:00 2001 From: "Aamir.Muhammad" Date: Wed, 19 Oct 2022 09:56:03 +0300 Subject: [PATCH 2/6] Chat Search User Api Implementation --- lib/api/chat/chat_provider_model.dart | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/api/chat/chat_provider_model.dart b/lib/api/chat/chat_provider_model.dart index fe95696..ea6ea13 100644 --- a/lib/api/chat/chat_provider_model.dart +++ b/lib/api/chat/chat_provider_model.dart @@ -69,16 +69,15 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { logger.d(response.statusCode); print(response.body); if (response.statusCode == 204) { - print(null); userChatHistory = []; } else { - userChatHistory = getSingleUserChatintoModel(response.body); + userChatHistory = getSingleUserChatModel(response.body); } isLoading = false; notifyListeners(); } - List getSingleUserChatintoModel(String str) => List.from(json.decode(str).map((x) => SingleUserChatModel.fromJson(x))); + List getSingleUserChatModel(String str) => List.from(json.decode(str).map((x) => SingleUserChatModel.fromJson(x))); ChatUserModel userToList(String str) => ChatUserModel.fromJson(json.decode(str)); @@ -195,7 +194,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { Future onMsgReceived(List? parameters) async { List data = []; for (dynamic msg in parameters!) { - data = getSingleUserChatintoModel(jsonEncode(msg)); + data = getSingleUserChatModel(jsonEncode(msg)); logger.d(msg); } userChatHistory.add(data.first); From 90b60ce55a53f9f8b428c491bf682f4a268fa529 Mon Sep 17 00:00:00 2001 From: "Aamir.Muhammad" Date: Wed, 19 Oct 2022 14:02:36 +0300 Subject: [PATCH 3/6] Chat Search User Api Implementation --- .../search_employee_bottom_sheet.dart | 180 +++++++++--------- 1 file changed, 85 insertions(+), 95 deletions(-) diff --git a/lib/widgets/bottom_sheets/search_employee_bottom_sheet.dart b/lib/widgets/bottom_sheets/search_employee_bottom_sheet.dart index 14da765..face11b 100644 --- a/lib/widgets/bottom_sheets/search_employee_bottom_sheet.dart +++ b/lib/widgets/bottom_sheets/search_employee_bottom_sheet.dart @@ -88,13 +88,7 @@ class _SearchEmployeeBottomSheetState extends State { void fetchChatUser({bool isNeedLoading = true}) async { try { Utils.showLoading(context); - chatUsersList = await ChatProviderModel().getChatMemberFromSearch(searchText, int.parse(AppState().chatDetails!.response!.id.toString())); - print("================================"); - print(jsonEncode(chatUsersList)); - // - // favouriteUserList = replacementList?.where((element) => element.isFavorite ?? false).toList(); - // nonFavouriteUserList = replacementList?.where((element) => !(element.isFavorite ?? false)).toList(); Utils.hideLoading(context); setState(() {}); } catch (e) { @@ -150,106 +144,102 @@ class _SearchEmployeeBottomSheetState extends State { icon: 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) + : 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 ? Utils.getNoDataWidget(context) : ListView( - physics: const BouncingScrollPhysics(), - padding: EdgeInsets.only(top: 0, bottom: 8), - children: [ - ListView.separated( - physics: const NeverScrollableScrollPhysics(), - shrinkWrap: true, - - itemBuilder: (cxt, index) { - return 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: 0, bottom: 8), + children: [ + ListView.separated( + physics: const NeverScrollableScrollPhysics(), + shrinkWrap: true, + itemBuilder: (cxt, index) { + return 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), - subtitle: (chatUsersList![index].isTyping == true ? "Something is Typing" : "Last message text").toText11(color: MyColors.normalTextColor), - trailing: ("Today").toText10(color: MyColors.lightTextColor), - minVerticalPadding: 0, - onTap: () { - Navigator.pop(context); - Navigator.pushNamed( - context, - AppRoutes.chatDetailed, - arguments: {"targetUser": chatUsersList![index]}, - ); - }, - ); - }, - separatorBuilder: (cxt, index) => Container( - height: 1, - color: MyColors.borderE3Color, - ), - itemCount: chatUsersList?.length ?? 0), - 12.height, - ], - ).expanded, + title: (chatUsersList![index].userName ?? "").toText14(color: MyColors.darkTextColor), + subtitle: (chatUsersList![index].isTyping == true ? "Something is Typing" : "Last message text").toText11(color: MyColors.normalTextColor), + trailing: ("Today").toText10(color: MyColors.lightTextColor), + minVerticalPadding: 0, + onTap: () { + Navigator.pop(context); + Navigator.pushNamed( + context, + AppRoutes.chatDetailed, + arguments: {"targetUser": chatUsersList![index]}, + ); + }, + ); + }, + separatorBuilder: (cxt, index) => Container( + height: 1, + color: MyColors.borderE3Color, + ), + 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(), From c29d003401450b6d677fa59c47112328fdfd31bd Mon Sep 17 00:00:00 2001 From: Sikander Saleem Date: Wed, 19 Oct 2022 14:11:36 +0300 Subject: [PATCH 4/6] services dynamic list issue fixed on payslip --- lib/ui/landing/widget/services_widget.dart | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/ui/landing/widget/services_widget.dart b/lib/ui/landing/widget/services_widget.dart index ecb0641..a6f4151 100644 --- a/lib/ui/landing/widget/services_widget.dart +++ b/lib/ui/landing/widget/services_widget.dart @@ -49,7 +49,6 @@ class ServicesWidget extends StatelessWidget { padding: const EdgeInsets.only(left: 21, right: 21, top: 13, bottom: 13), scrollDirection: Axis.horizontal, itemBuilder: (cxt, index) { - return AspectRatio( aspectRatio: 105 / 105, child: data.isServicesMenusLoading @@ -77,11 +76,7 @@ class ServicesWidget extends StatelessWidget { Expanded( child: data.homeMenus![parentIndex].menuEntiesList[index].prompt!.toText10(isBold: true), ), - RotatedBox( - quarterTurns: AppState().isArabic(context) ? 2:4, - child: SvgPicture.asset("assets/images/arrow_next.svg").paddingOnly(bottom: 4) - ), - + RotatedBox(quarterTurns: AppState().isArabic(context) ? 2 : 4, child: SvgPicture.asset("assets/images/arrow_next.svg").paddingOnly(bottom: 4)), ], ) ], @@ -119,7 +114,7 @@ class ServicesWidget extends StatelessWidget { Navigator.of(context).pushNamed(AppRoutes.profile); return; } - List menuList = pro.getMenuEntriesList?.where((element) => element.parentMenuName == menuEntry.menuName && (element.menuEntryType == "FUNCTION" || element.menuEntryType == "MENU")).toList() ?? []; + List menuList = pro.getMenuEntriesList?.where((element) => element.parentMenuName == menuEntry.menuName && (element.menuEntryType == "FUNCTION")).toList() ?? []; menuEntry.icon = ""; if (menuList.isEmpty) { if (menuEntry.requestType == "EIT") { @@ -128,7 +123,12 @@ class ServicesWidget extends StatelessWidget { Navigator.pushNamed(context, AppRoutes.monthlyPaySlip); } } else { - Navigator.pushNamed(context, AppRoutes.servicesMenuListScreen, arguments: ServicesMenuListScreenParams(menuEntry.prompt!, menuList)); + List _menuList = pro.getMenuEntriesList?.where((element) => element.parentMenuName == menuEntry.menuName && (element.menuEntryType == "FUNCTION" || element.menuEntryType == "MENU")).toList() ?? []; + if (_menuList.isEmpty) { + Navigator.pushNamed(context, AppRoutes.servicesMenuListScreen, arguments: ServicesMenuListScreenParams(menuEntry.prompt!, menuList)); + } else { + Navigator.pushNamed(context, AppRoutes.servicesMenuListScreen, arguments: ServicesMenuListScreenParams(menuEntry.prompt!, _menuList)); + } } return; } From 0213a7a4ef1a7bbdc14836a2b3443a6376535ad5 Mon Sep 17 00:00:00 2001 From: Sikander Saleem Date: Wed, 19 Oct 2022 16:34:08 +0300 Subject: [PATCH 5/6] worklist api calling delay fixed. --- lib/ui/landing/widget/services_widget.dart | 9 +- lib/ui/work_list/worklist_detail_screen.dart | 385 +++++++++++++++---- 2 files changed, 311 insertions(+), 83 deletions(-) diff --git a/lib/ui/landing/widget/services_widget.dart b/lib/ui/landing/widget/services_widget.dart index a6f4151..80328a1 100644 --- a/lib/ui/landing/widget/services_widget.dart +++ b/lib/ui/landing/widget/services_widget.dart @@ -123,12 +123,9 @@ class ServicesWidget extends StatelessWidget { Navigator.pushNamed(context, AppRoutes.monthlyPaySlip); } } else { - List _menuList = pro.getMenuEntriesList?.where((element) => element.parentMenuName == menuEntry.menuName && (element.menuEntryType == "FUNCTION" || element.menuEntryType == "MENU")).toList() ?? []; - if (_menuList.isEmpty) { - Navigator.pushNamed(context, AppRoutes.servicesMenuListScreen, arguments: ServicesMenuListScreenParams(menuEntry.prompt!, menuList)); - } else { - Navigator.pushNamed(context, AppRoutes.servicesMenuListScreen, arguments: ServicesMenuListScreenParams(menuEntry.prompt!, _menuList)); - } + List _menuList = + pro.getMenuEntriesList?.where((element) => element.parentMenuName == menuEntry.menuName && (element.menuEntryType == "FUNCTION" || element.menuEntryType == "MENU")).toList() ?? []; + Navigator.pushNamed(context, AppRoutes.servicesMenuListScreen, arguments: ServicesMenuListScreenParams(menuEntry.prompt!, _menuList.isEmpty ? menuList : _menuList)); } return; } diff --git a/lib/ui/work_list/worklist_detail_screen.dart b/lib/ui/work_list/worklist_detail_screen.dart index 241b2e8..c20ceba 100644 --- a/lib/ui/work_list/worklist_detail_screen.dart +++ b/lib/ui/work_list/worklist_detail_screen.dart @@ -93,92 +93,73 @@ class _WorkListDetailScreenState extends State { } void getData() async { - try { - Utils.showLoading(context); - if (workListData!.iTEMTYPE == "HRSSA" || workListData!.iTEMTYPE == "STAMP") { - memberInformationListModel = await WorkListApiClient().getUserInformation(-999, workListData!.sELECTEDEMPLOYEENUMBER!); - } - if (workListData!.iTEMTYPE == "HRSSA") { - if (workListData!.rEQUESTTYPE == "EIT") { - getEitCollectionNotificationBodyList = await WorkListApiClient().GetEitNotificationBody(workListData!.nOTIFICATIONID); - } else if (workListData!.rEQUESTTYPE == "PHONE_NUMBERS") { - getPhonesNotificationBodyList = await WorkListApiClient().getPhonesNotificationBodyList(workListData!.nOTIFICATIONID); - } else if (workListData!.rEQUESTTYPE == "BASIC_DETAILS") { - getBasicDetNtfBodyList = await WorkListApiClient().getBasicDetNtfBodyList(workListData!.nOTIFICATIONID); - } else if (workListData!.rEQUESTTYPE == "ABSENCE") { - getAbsenceCollectionNotificationBodyList = await WorkListApiClient().getAbsenceNotificationBody(workListData!.nOTIFICATIONID); - } else if (workListData!.rEQUESTTYPE == "CONTACT") { - getContactNotificationBodyList = await WorkListApiClient().getContactNotificationBodyList(workListData!.nOTIFICATIONID); - } - - // getBasicNTFBody = await WorkListApiClient().getBasicDetNTFBody(workListData!.nOTIFICATIONID!, -999); - // getAbsenceCollectionNotifications = await WorkListApiClient().getAbsenceNotificationBody(workListData!.nOTIFICATIONID!, -999); - // subordinatesLeavesModel = await WorkListApiClient().getSubordinatesLeaves("", ""); - } - if (workListData!.iTEMTYPE == "STAMP") { - if (workListData!.rEQUESTTYPE == "STAMP_MS") { - getStampMsNotifications = await WorkListApiClient().getStampMsNotificationBody(workListData!.nOTIFICATIONID!, -999); - } else { - getStampNsNotifications = await WorkListApiClient().getStampNsNotificationBody(workListData!.nOTIFICATIONID!, -999); - } - } - if (workListData!.iTEMTYPE == "INVMOA") { - getMoNotificationBodyList = await WorkListApiClient().getMoNotificationBody(workListData!.nOTIFICATIONID!, -999); - } - if (workListData!.iTEMTYPE == "INVITEM") { - getItemCreationNtfBody = await WorkListApiClient().getItemCreationNtfBody(workListData!.nOTIFICATIONID!, -999); - } - if (workListData!.iTEMTYPE == "POAPPRV") { - getPoNotificationBody = await WorkListApiClient().getPoNotificationBody(workListData!.nOTIFICATIONID!, -999); - } - getNotificationRespondAttributes = await WorkListApiClient().notificationGetRespondAttributes(workListData!.nOTIFICATIONID!); - if (getNotificationRespondAttributes.isNotEmpty) { - notificationNoteInput = getNotificationRespondAttributes.first; + // try { + // Utils.showLoading(context); + if (workListData!.iTEMTYPE == "HRSSA" || workListData!.iTEMTYPE == "STAMP") { + getUserInformation(); + } + if (workListData!.iTEMTYPE == "HRSSA") { + if (workListData!.rEQUESTTYPE == "EIT") { + getEitNotificationBody(); + } else if (workListData!.rEQUESTTYPE == "PHONE_NUMBERS") { + getPhonesNotificationBody(); + } else if (workListData!.rEQUESTTYPE == "BASIC_DETAILS") { + getBasicDetNtfBody(); + } else if (workListData!.rEQUESTTYPE == "ABSENCE") { + getAbsenceNotificationBody(); + } else if (workListData!.rEQUESTTYPE == "CONTACT") { + getContactNotificationBody(); } + // getBasicNTFBody = await WorkListApiClient().getBasicDetNTFBody(workListData!.nOTIFICATIONID!, -999); + // getAbsenceCollectionNotifications = await WorkListApiClient().getAbsenceNotificationBody(workListData!.nOTIFICATIONID!, -999); + // subordinatesLeavesModel = await WorkListApiClient().getSubordinatesLeaves("", ""); + } + if (workListData!.iTEMTYPE == "STAMP") { + getStampNotificationBody(); + } + if (workListData!.iTEMTYPE == "INVMOA") { + getMoNotificationBody(); + } + if (workListData!.iTEMTYPE == "INVITEM") { + getItemCreationNtf(); + } + if (workListData!.iTEMTYPE == "POAPPRV") { + getPoNotification(); + } + notificationGetRespondAttributes(); - List dataToFetch = await Future.wait([ - WorkListApiClient().getNotificationButtons(workListData!.nOTIFICATIONID!), - WorkListApiClient().getActionHistory(workListData!.nOTIFICATIONID!), - WorkListApiClient().getAttachments(workListData!.nOTIFICATIONID!), - ]); - - notificationButtonsList = dataToFetch[0]; - actionHistoryList = dataToFetch[1]; - getAttachmentList = dataToFetch[2]; - - // List futureRequest = []; - // List futureObject = []; - // - // addRequestInFuture(notificationButtonsList, WorkListApiClient().getNotificationButtons(workListData!.nOTIFICATIONID!)); - // addRequestInFuture(actionHistoryList, WorkListApiClient().getActionHistory(workListData!.nOTIFICATIONID!)); - // addRequestInFuture(getAttachmentList, WorkListApiClient().getAttachments(workListData!.nOTIFICATIONID!)); + // List dataToFetch = await Future.wait([ + // + // WorkListApiClient().getActionHistory(workListData!.nOTIFICATIONID!), + // WorkListApiClient().getAttachments(workListData!.nOTIFICATIONID!), + // ]); + // + // notificationButtonsList = dataToFetch[0]; + // actionHistoryList = dataToFetch[1]; + // getAttachmentList = dataToFetch[2]; - // List dataToFetch = await Future.wait(futureRequest); - // for(int i=0;i element.bUTTONACTION == "CLOSE"); - isApproveAvailable = notificationButtonsList.any((element) => element.bUTTONACTION == "APPROVED"); - isRejectAvailable = notificationButtonsList.any((element) => element.bUTTONACTION == "REJECTED"); - } - Utils.hideLoading(context); - setState(() {}); - } catch (ex) { - Utils.hideLoading(context); - Utils.handleException(ex, context, null); - setState(() {}); - } + // if (notificationButtonsList.isNotEmpty) { + // isCloseAvailable = notificationButtonsList.any((element) => element.bUTTONACTION == "CLOSE"); + // isApproveAvailable = notificationButtonsList.any((element) => element.bUTTONACTION == "APPROVED"); + // isRejectAvailable = notificationButtonsList.any((element) => element.bUTTONACTION == "REJECTED"); + // } + // Utils.hideLoading(context); + // setState(() {}); + // } catch (ex) { + // Utils.hideLoading(context); + // Utils.handleException(ex, context, null); + // setState(() {}); + // } } List futureRequest = []; List futureObject = []; - void addRequestInFuture(data, request) { - futureObject.add(data); - futureRequest.add(request); - } + int apiCallCount = 0; void getDataFromState() { if (workListData == null) { @@ -531,4 +512,254 @@ class _WorkListDetailScreenState extends State { Utils.handleException(ex, context, null); } } + + void getEitNotificationBody() async { + try { + if (apiCallCount == 0) Utils.showLoading(context); + apiCallCount++; + getEitCollectionNotificationBodyList = await WorkListApiClient().GetEitNotificationBody(workListData!.nOTIFICATIONID); + apiCallCount--; + if (apiCallCount == 0) { + Utils.hideLoading(context); + setState(() {}); + } + } catch (ex) { + apiCallCount--; + Utils.hideLoading(context); + Utils.handleException(ex, context, null); + } + } + + void getUserInformation() async { + try { + if (apiCallCount == 0) Utils.showLoading(context); + apiCallCount++; + memberInformationListModel = await WorkListApiClient().getUserInformation(-999, workListData!.sELECTEDEMPLOYEENUMBER!); + apiCallCount--; + if (apiCallCount == 0) { + Utils.hideLoading(context); + setState(() {}); + } + } catch (ex) { + apiCallCount--; + Utils.hideLoading(context); + Utils.handleException(ex, context, null); + } + } + + void getPhonesNotificationBody() async { + try { + if (apiCallCount == 0) Utils.showLoading(context); + apiCallCount++; + getPhonesNotificationBodyList = await WorkListApiClient().getPhonesNotificationBodyList(workListData!.nOTIFICATIONID); + apiCallCount--; + if (apiCallCount == 0) { + Utils.hideLoading(context); + setState(() {}); + } + } catch (ex) { + apiCallCount--; + Utils.hideLoading(context); + Utils.handleException(ex, context, null); + } + } + + void getBasicDetNtfBody() async { + try { + if (apiCallCount == 0) Utils.showLoading(context); + apiCallCount++; + getBasicDetNtfBodyList = await WorkListApiClient().getBasicDetNtfBodyList(workListData!.nOTIFICATIONID); + apiCallCount--; + if (apiCallCount == 0) { + Utils.hideLoading(context); + setState(() {}); + } + } catch (ex) { + apiCallCount--; + Utils.hideLoading(context); + Utils.handleException(ex, context, null); + } + } + + void getAbsenceNotificationBody() async { + try { + if (apiCallCount == 0) Utils.showLoading(context); + apiCallCount++; + getAbsenceCollectionNotificationBodyList = await WorkListApiClient().getAbsenceNotificationBody(workListData!.nOTIFICATIONID); + apiCallCount--; + if (apiCallCount == 0) { + Utils.hideLoading(context); + setState(() {}); + } + } catch (ex) { + apiCallCount--; + Utils.hideLoading(context); + Utils.handleException(ex, context, null); + } + } + + void getContactNotificationBody() async { + try { + if (apiCallCount == 0) Utils.showLoading(context); + apiCallCount++; + getContactNotificationBodyList = await WorkListApiClient().getContactNotificationBodyList(workListData!.nOTIFICATIONID); + apiCallCount--; + if (apiCallCount == 0) { + Utils.hideLoading(context); + setState(() {}); + } + } catch (ex) { + apiCallCount--; + Utils.hideLoading(context); + Utils.handleException(ex, context, null); + } + } + + void getStampNotificationBody() async { + try { + if (apiCallCount == 0) Utils.showLoading(context); + apiCallCount++; + if (workListData!.rEQUESTTYPE == "STAMP_MS") { + getStampMsNotifications = await WorkListApiClient().getStampMsNotificationBody(workListData!.nOTIFICATIONID!, -999); + } else { + getStampNsNotifications = await WorkListApiClient().getStampNsNotificationBody(workListData!.nOTIFICATIONID!, -999); + } + apiCallCount--; + if (apiCallCount == 0) { + Utils.hideLoading(context); + setState(() {}); + } + } catch (ex) { + apiCallCount--; + Utils.hideLoading(context); + Utils.handleException(ex, context, null); + } + } + + void getMoNotificationBody() async { + try { + if (apiCallCount == 0) Utils.showLoading(context); + apiCallCount++; + getMoNotificationBodyList = await WorkListApiClient().getMoNotificationBody(workListData!.nOTIFICATIONID!, -999); + apiCallCount--; + if (apiCallCount == 0) { + Utils.hideLoading(context); + setState(() {}); + } + } catch (ex) { + apiCallCount--; + Utils.hideLoading(context); + Utils.handleException(ex, context, null); + } + } + + void getItemCreationNtf() async { + try { + if (apiCallCount == 0) Utils.showLoading(context); + apiCallCount++; + getItemCreationNtfBody = await WorkListApiClient().getItemCreationNtfBody(workListData!.nOTIFICATIONID!, -999); + apiCallCount--; + if (apiCallCount == 0) { + Utils.hideLoading(context); + setState(() {}); + } + } catch (ex) { + apiCallCount--; + Utils.hideLoading(context); + Utils.handleException(ex, context, null); + } + } + + void getPoNotification() async { + try { + if (apiCallCount == 0) Utils.showLoading(context); + apiCallCount++; + getPoNotificationBody = await WorkListApiClient().getPoNotificationBody(workListData!.nOTIFICATIONID!, -999); + apiCallCount--; + if (apiCallCount == 0) { + Utils.hideLoading(context); + setState(() {}); + } + } catch (ex) { + apiCallCount--; + Utils.hideLoading(context); + Utils.handleException(ex, context, null); + } + } + + void notificationGetRespondAttributes() async { + try { + if (apiCallCount == 0) Utils.showLoading(context); + apiCallCount++; + getNotificationRespondAttributes = await WorkListApiClient().notificationGetRespondAttributes(workListData!.nOTIFICATIONID!); + if (getNotificationRespondAttributes.isNotEmpty) { + notificationNoteInput = getNotificationRespondAttributes.first; + } + apiCallCount--; + if (apiCallCount == 0) { + Utils.hideLoading(context); + setState(() {}); + } + } catch (ex) { + apiCallCount--; + Utils.hideLoading(context); + Utils.handleException(ex, context, null); + } + } + + void getNotificationButtons() async { + try { + if (apiCallCount == 0) Utils.showLoading(context); + apiCallCount++; + notificationButtonsList = await WorkListApiClient().getNotificationButtons(workListData!.nOTIFICATIONID!); + if (notificationButtonsList.isNotEmpty) { + isCloseAvailable = notificationButtonsList.any((element) => element.bUTTONACTION == "CLOSE"); + isApproveAvailable = notificationButtonsList.any((element) => element.bUTTONACTION == "APPROVED"); + isRejectAvailable = notificationButtonsList.any((element) => element.bUTTONACTION == "REJECTED"); + } + apiCallCount--; + if (apiCallCount == 0) { + Utils.hideLoading(context); + setState(() {}); + } + } catch (ex) { + apiCallCount--; + Utils.hideLoading(context); + Utils.handleException(ex, context, null); + } + } + + void getActionHistory() async { + try { + if (apiCallCount == 0) Utils.showLoading(context); + apiCallCount++; + actionHistoryList = await WorkListApiClient().getActionHistory(workListData!.nOTIFICATIONID!); + apiCallCount--; + if (apiCallCount == 0) { + Utils.hideLoading(context); + setState(() {}); + } + } catch (ex) { + apiCallCount--; + Utils.hideLoading(context); + Utils.handleException(ex, context, null); + } + } + + void getAttachments() async { + try { + // if (apiCallCount == 0) Utils.showLoading(context); + // apiCallCount++; + getAttachmentList = await WorkListApiClient().getAttachments(workListData!.nOTIFICATIONID!); + // apiCallCount--; + // if (apiCallCount == 0) { + // Utils.hideLoading(context); + setState(() {}); + // } + } catch (ex) { + // apiCallCount--; + // Utils.hideLoading(context); + Utils.handleException(ex, context, null); + } + } } From e7d2299b43fd9787f206fd37420066e4b059ff09 Mon Sep 17 00:00:00 2001 From: Sikander Saleem Date: Wed, 19 Oct 2022 16:38:46 +0300 Subject: [PATCH 6/6] improvement. --- lib/ui/work_list/worklist_detail_screen.dart | 25 ++++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/lib/ui/work_list/worklist_detail_screen.dart b/lib/ui/work_list/worklist_detail_screen.dart index 1fbab01..4494eb6 100644 --- a/lib/ui/work_list/worklist_detail_screen.dart +++ b/lib/ui/work_list/worklist_detail_screen.dart @@ -127,7 +127,7 @@ class _WorkListDetailScreenState extends State { getPoNotification(); } if (workListData!.iTEMTYPE == "REQAPPRV") { - getPrNotificationBody = await WorkListApiClient().getPRNotificationBody(workListData!.nOTIFICATIONID!, -999); + getPRNotification(); } notificationGetRespondAttributes(); @@ -471,9 +471,7 @@ class _WorkListDetailScreenState extends State { child: isIconAsset ? SvgPicture.asset(icon) : Image.memory( - Utils.dataFromBase64String( - icon - ), + Utils.dataFromBase64String(icon), fit: BoxFit.cover, ), ) @@ -490,7 +488,7 @@ class _WorkListDetailScreenState extends State { notificationGetRespond: notificationNoteInput, textEditingController: textEditingController, onTap: (note) { - if(note.isNotEmpty && (actionMode == "APPROVED" || actionMode == "APPROVE")) { + if (note.isNotEmpty && (actionMode == "APPROVED" || actionMode == "APPROVE")) { Map payload = { "P_ACTION_MODE": actionMode, "P_APPROVER_INDEX": null, @@ -701,6 +699,23 @@ class _WorkListDetailScreenState extends State { } } + void getPRNotification() async { + try { + if (apiCallCount == 0) Utils.showLoading(context); + apiCallCount++; + getPrNotificationBody = await WorkListApiClient().getPRNotificationBody(workListData!.nOTIFICATIONID!, -999); + apiCallCount--; + if (apiCallCount == 0) { + Utils.hideLoading(context); + setState(() {}); + } + } catch (ex) { + apiCallCount--; + Utils.hideLoading(context); + Utils.handleException(ex, context, null); + } + } + void notificationGetRespondAttributes() async { try { if (apiCallCount == 0) Utils.showLoading(context);