From a0c5ac7e6c85a2455c09aee1623614e8f6ad2056 Mon Sep 17 00:00:00 2001 From: FaizHashmi Date: Tue, 20 Oct 2026 11:23:46 +0300 Subject: [PATCH] Toast fixed --- lib/classes/utils.dart | 18 +++++++++--- .../attendance/add_vacation_rule_screen.dart | 2 +- .../dashboard_screen_for_dependet.dart | 12 ++++---- .../itg/change_itg_ad_password_screen.dart | 2 +- lib/ui/landing/itg/survey_screen.dart | 2 +- .../wala_plus_retailer_details_screen.dart | 28 ++++--------------- lib/ui/login/change_password_screen.dart | 2 +- lib/ui/login/login_screen.dart | 2 +- lib/ui/login/new_password_screen.dart | 2 +- lib/ui/misc/request_submit_screen.dart | 2 +- .../profile/add_dependent_verify_screen.dart | 2 +- .../profile/mazaya_access_result_screen.dart | 2 +- .../fragments/item_review_fragment.dart | 2 +- .../mowadhafhi/mowadhafhi_hr_request.dart | 2 +- lib/ui/work_list/itg_detail_screen.dart | 10 +++---- lib/ui/work_list/worklist_detail_screen.dart | 2 +- 16 files changed, 44 insertions(+), 48 deletions(-) diff --git a/lib/classes/utils.dart b/lib/classes/utils.dart index 15bff81..548dec4 100644 --- a/lib/classes/utils.dart +++ b/lib/classes/utils.dart @@ -33,10 +33,20 @@ class Utils { // longDuration is accepted but no longer varies the duration - every caller already used the // default (true), so AppToast.plainSeconds covers both cases with one fixed value. - // Soft red bg + red text - same combo already used elsewhere in the app for - // expired/inactive-style chips (e.g. dependent_details_screen.dart's "Access Off" badge). - static void showToast(String message, {bool longDuration = true}) { - AppToast.show( message, seconds: AppToast.plainSeconds, showIcon: false, showCountdownText: true, bgColor: const Color(0xFFF1CECE), textColor: const Color(0xFFC53030)); + // isSuccess: true -> soft green/green (same combo as dependent_details_screen.dart's "Active" + // badge); false (default) -> soft red/red (same combo as that screen's "Access Off" badge). + // Callers showing a value straight from an API response should pass isSuccess: response's + // MessageStatus == 1; everywhere else (validation messages, caught errors) just defaults to + // red, and the handful of hardcoded success confirmations pass isSuccess: true explicitly. + static void showToast(String message, {bool longDuration = true, bool isSuccess = false}) { + AppToast.show( + message, + seconds: AppToast.plainSeconds, + showIcon: false, + showCountdownText: true, + bgColor: isSuccess ? const Color(0xFFECFDF5) : const Color(0xFFF1CECE), + textColor: isSuccess ? const Color(0xFF059669) : const Color(0xFFC53030), + ); } static dynamic getNotNullValue(List list, int index) { diff --git a/lib/ui/attendance/add_vacation_rule_screen.dart b/lib/ui/attendance/add_vacation_rule_screen.dart index 52eab3d..4d8d595 100644 --- a/lib/ui/attendance/add_vacation_rule_screen.dart +++ b/lib/ui/attendance/add_vacation_rule_screen.dart @@ -216,7 +216,7 @@ class _AddVacationRuleScreenState extends State { CreateVacationRuleList? createVacationRuleList = await VacationRuleApiClient().createVacationRule(DateUtil.convertDateToStringLocation(startTime), DateUtil.convertDateToStringLocation(endTime!), selectedItemType!.iTEMTYPE!, selectedItemTypeNotification!.nOTIFICATIONNAME!, message, getPAction(), selectedReplacementEmployee!.userName!, respondAttributeList); Utils.hideLoading(context); - Utils.showToast(LocaleKeys.vacationRuleAdded.tr()); + Utils.showToast(LocaleKeys.vacationRuleAdded.tr(), isSuccess: true); Navigator.popUntil(context, ModalRoute.withName(AppRoutes.dashboard)); } catch (ex) { Utils.hideLoading(context); diff --git a/lib/ui/landing/dashboard_screen_for_dependet.dart b/lib/ui/landing/dashboard_screen_for_dependet.dart index 1bc7171..fbe9102 100644 --- a/lib/ui/landing/dashboard_screen_for_dependet.dart +++ b/lib/ui/landing/dashboard_screen_for_dependet.dart @@ -296,10 +296,12 @@ class _DashboardScreenForDependetState extends State sortBy: _filterSortBy, radius: radiusParam, minDiscount: minDiscountParam, - // Same as getWalaPlusRetailerById: always pass context whenever we have one so - // WP_Geo_Location is attempted - don't gate it on wantsNearest, that only matters for - // whether we block the fetch to prompt for permission first (see the gate above). - context: context, + // _getCurrentPositionSilently (triggered whenever context is non-null) isn't actually + // silent - it calls Geolocator.requestPermission() if permission hasn't been + // granted/denied yet, which pops the real OS permission dialog. Only pass context when + // Nearest is actually selected, otherwise every fetch (including the default newest-sort + // load on app start) would trigger that prompt for no reason. + context: wantsNearest ? context : null, ); retailersList = response?.retailers ?? []; @@ -356,7 +358,7 @@ class _DashboardScreenForDependetState extends State sortBy: _filterSortBy, radius: radiusParam, minDiscount: minDiscountParam, - context: context, + context: wantsNearest ? context : null, ); List newRetailers = response?.retailers ?? []; diff --git a/lib/ui/landing/itg/change_itg_ad_password_screen.dart b/lib/ui/landing/itg/change_itg_ad_password_screen.dart index cc84f96..a8d7650 100644 --- a/lib/ui/landing/itg/change_itg_ad_password_screen.dart +++ b/lib/ui/landing/itg/change_itg_ad_password_screen.dart @@ -41,7 +41,7 @@ class _ChangeItgAdPasswordScreenState extends State { GenericResponseModel response = await LoginApiClient().changePasswordFromActiveDirectorySession(password.text, AppState().memberInformationList!.eMPLOYEEEMAILADDRESS!); Utils.hideLoading(context); if ((response.messageStatus ?? 0) == 1) { - Utils.showToast(LocaleKeys.passwordChangedSuccessfully.tr()); + Utils.showToast(LocaleKeys.passwordChangedSuccessfully.tr(), isSuccess: true); Navigator.pop(context); } } catch (ex) { diff --git a/lib/ui/landing/itg/survey_screen.dart b/lib/ui/landing/itg/survey_screen.dart index 3bbb27f..20a2bb9 100644 --- a/lib/ui/landing/itg/survey_screen.dart +++ b/lib/ui/landing/itg/survey_screen.dart @@ -222,7 +222,7 @@ class _SurveyScreenState extends State { Utils.hideLoading(context); if (res!.mohemmItgResponseItem!.statusCode == 200) { - Utils.showToast("Survey has been submitted successfully"); + Utils.showToast("Survey has been submitted successfully", isSuccess: true); Navigator.pop(context); } else { Utils.showToast(res.mohemmItgResponseItem!.message.toString()); diff --git a/lib/ui/landing/wala_plus_retailer_details_screen.dart b/lib/ui/landing/wala_plus_retailer_details_screen.dart index 1edbb04..5426832 100644 --- a/lib/ui/landing/wala_plus_retailer_details_screen.dart +++ b/lib/ui/landing/wala_plus_retailer_details_screen.dart @@ -112,11 +112,7 @@ class _WalaPlusRetailerDetailsScreenState extends State { try { var genericResponseModel = await LoginApiClient().changePasswordFromActiveSession(oldPassword.text, password.text, confirmPassword.text); Utils.hideLoading(context); - Utils.showToast(LocaleKeys.passwordChangedSuccessfully.tr()); + Utils.showToast(LocaleKeys.passwordChangedSuccessfully.tr(), isSuccess: true); Navigator.pop(context); } catch (ex) { Utils.hideLoading(context); diff --git a/lib/ui/login/login_screen.dart b/lib/ui/login/login_screen.dart index e637e93..6e440f6 100644 --- a/lib/ui/login/login_screen.dart +++ b/lib/ui/login/login_screen.dart @@ -775,7 +775,7 @@ class _LoginScreenState extends State { try { await LoginApiClient().mohemmSendOTPDependent(nationalId: nationalId.text.trim(), mobileNumber: mobileNumber, logInTokenID: logInTokenID, context: context); Utils.hideLoading(context); - Utils.showToast(LocaleKeys.verificationCodeResent.tr()); + Utils.showToast(LocaleKeys.verificationCodeResent.tr(), isSuccess: true); _showDependentOtpDialog(logInTokenID, mobileNumber); } catch (ex) { Utils.hideLoading(context); diff --git a/lib/ui/login/new_password_screen.dart b/lib/ui/login/new_password_screen.dart index 70b7456..96ea18e 100644 --- a/lib/ui/login/new_password_screen.dart +++ b/lib/ui/login/new_password_screen.dart @@ -41,7 +41,7 @@ class _NewPasswordScreenState extends State { try { var genericResponseModel = await LoginApiClient().changePasswordForget(AppState().getForgetPasswordTokenID ?? "", password.text, confirmPassword.text, userName); Utils.hideLoading(context); - Utils.showToast(LocaleKeys.passwordChangedSuccessfully.tr()); + Utils.showToast(LocaleKeys.passwordChangedSuccessfully.tr(), isSuccess: true); Navigator.pop(context); } catch (ex) { print(ex); diff --git a/lib/ui/misc/request_submit_screen.dart b/lib/ui/misc/request_submit_screen.dart index 230223b..472e3c6 100644 --- a/lib/ui/misc/request_submit_screen.dart +++ b/lib/ui/misc/request_submit_screen.dart @@ -145,7 +145,7 @@ class _RequestSubmitScreenState extends State { ); } else {} Utils.hideLoading(context); - Utils.showToast(LocaleKeys.yourRequestHasBeenSubmittedForApprovals.tr(), longDuration: true); + Utils.showToast(LocaleKeys.yourRequestHasBeenSubmittedForApprovals.tr(), longDuration: true, isSuccess: true); AppState().cancelRequestTrancsection = false; if (params?.popNavigateToSpecificRoute == null) { diff --git a/lib/ui/profile/add_dependent_verify_screen.dart b/lib/ui/profile/add_dependent_verify_screen.dart index c3f66ae..e493fb9 100644 --- a/lib/ui/profile/add_dependent_verify_screen.dart +++ b/lib/ui/profile/add_dependent_verify_screen.dart @@ -1827,7 +1827,7 @@ class _AddDependentVerifyScreenState extends State { Utils.hideLoading(context); Navigator.pop(context); } else { - Utils.showToast(LocaleKeys.dependentAddedSuccessfully.tr()); + Utils.showToast(LocaleKeys.dependentAddedSuccessfully.tr(), isSuccess: true); Navigator.pop(context); } } catch (ex) { diff --git a/lib/ui/profile/mazaya_access_result_screen.dart b/lib/ui/profile/mazaya_access_result_screen.dart index 5b9a233..dd43f00 100644 --- a/lib/ui/profile/mazaya_access_result_screen.dart +++ b/lib/ui/profile/mazaya_access_result_screen.dart @@ -529,7 +529,7 @@ class MazayaAccessResultScreen extends StatelessWidget { LocaleKeys.copyLink.tr(), () { Clipboard.setData(ClipboardData(text: _buildMazayaInviteMessage(linkToShare, nationalId, dateOfBirth))); - Utils.showToast(LocaleKeys.linkCopied.tr()); + Utils.showToast(LocaleKeys.linkCopied.tr(), isSuccess: true); }, colors: const [Colors.white, Colors.white], border: Border.all(color: const Color(0xFFCBD5E1)), diff --git a/lib/ui/screens/items_for_sale/fragments/item_review_fragment.dart b/lib/ui/screens/items_for_sale/fragments/item_review_fragment.dart index 1e3581a..de67d2e 100644 --- a/lib/ui/screens/items_for_sale/fragments/item_review_fragment.dart +++ b/lib/ui/screens/items_for_sale/fragments/item_review_fragment.dart @@ -146,7 +146,7 @@ class _ItemReviewFragmentState extends State { Utils.showLoading(context); String message = await ItemsForSaleApiClient().addItemForSale(itemReviewModel!, imagesList); Utils.hideLoading(context); - Utils.showToast(message); + Utils.showToast(message, isSuccess: true); Navigator.of(context).pop(); setState(() {}); } catch (ex) { diff --git a/lib/ui/screens/mowadhafhi/mowadhafhi_hr_request.dart b/lib/ui/screens/mowadhafhi/mowadhafhi_hr_request.dart index b358843..7e307f9 100644 --- a/lib/ui/screens/mowadhafhi/mowadhafhi_hr_request.dart +++ b/lib/ui/screens/mowadhafhi/mowadhafhi_hr_request.dart @@ -382,7 +382,7 @@ class _MowadhafhiHRRequestState extends State { } int? messageStatus = await MowadhafhiApiClient().submitRequest(selectedDepartment?.projectDepartmentId, description, projectID, selectedSection?.departmentSectionId.toString(), selectedTopic?.sectionTopicId.toString(), selectedServiceType!.ticketTypeId, list); - Utils.showToast(LocaleKeys.requestCreatedSuccessfully.tr()); + Utils.showToast(LocaleKeys.requestCreatedSuccessfully.tr(), isSuccess: true); Utils.hideLoading(context); Navigator.pop(context); } catch (ex) { diff --git a/lib/ui/work_list/itg_detail_screen.dart b/lib/ui/work_list/itg_detail_screen.dart index fdfe19c..1caba54 100644 --- a/lib/ui/work_list/itg_detail_screen.dart +++ b/lib/ui/work_list/itg_detail_screen.dart @@ -480,7 +480,7 @@ class _ItgDetailScreenState extends State { AppState().memberInformationList?.eMPLOYEEEMAILADDRESS ?? "", ); Utils.hideLoading(context); - Utils.showToast(LocaleKeys.yourChangeHasBeenSavedSuccessfully.tr()); + Utils.showToast(LocaleKeys.yourChangeHasBeenSavedSuccessfully.tr(), isSuccess: true); // Navigator.pop(context, "delegate_reload"); AppState().requestAllList!.removeAt(AppState().itgWorkListIndex!); if (AppState().requestAllList!.isEmpty) { @@ -504,7 +504,7 @@ class _ItgDetailScreenState extends State { Utils.showLoading(context); ITGRequest? itgRequest = await WorkListApiClient().answerITGRequest(requestType, taskId, itemId, employeeNumber, "", comments); Utils.hideLoading(context); - Utils.showToast(LocaleKeys.yourChangeHasBeenSavedSuccessfully.tr()); + Utils.showToast(LocaleKeys.yourChangeHasBeenSavedSuccessfully.tr(), isSuccess: true); // Navigator.pop(context, "delegate_reload"); AppState().requestAllList!.removeAt(AppState().itgWorkListIndex!); if (AppState().requestAllList!.isEmpty) { @@ -528,7 +528,7 @@ class _ItgDetailScreenState extends State { Utils.showLoading(context); ITGRequest? itgRequest = await WorkListApiClient().rejectITGRequest(requestType, taskId, itemId, employeeNumber, comments); Utils.hideLoading(context); - Utils.showToast(LocaleKeys.yourChangeHasBeenSavedSuccessfully.tr()); + Utils.showToast(LocaleKeys.yourChangeHasBeenSavedSuccessfully.tr(), isSuccess: true); // Navigator.pop(context, "delegate_reload"); AppState().requestAllList!.removeAt(AppState().itgWorkListIndex!); if (AppState().requestAllList!.isEmpty) { @@ -552,7 +552,7 @@ class _ItgDetailScreenState extends State { Utils.showLoading(context); ITGRequest? itgRequest = await WorkListApiClient().approveITGRequest(requestType, taskId, itemId, employeeNumber, comments); Utils.hideLoading(context); - Utils.showToast(LocaleKeys.yourChangeHasBeenSavedSuccessfully.tr()); + Utils.showToast(LocaleKeys.yourChangeHasBeenSavedSuccessfully.tr(), isSuccess: true); // Navigator.pop(context, "delegate_reload"); animationIndex = animationIndex + 1; AppState().requestAllList!.removeAt(AppState().itgWorkListIndex!); @@ -578,7 +578,7 @@ class _ItgDetailScreenState extends State { animationIndex = animationIndex + 1; ITGRequest? itgRequest = await WorkListApiClient().grantITGRequest(requestType, taskId, itemId, employeeNumber, "", ""); Utils.hideLoading(context); - Utils.showToast(LocaleKeys.yourChangeHasBeenSavedSuccessfully.tr()); + Utils.showToast(LocaleKeys.yourChangeHasBeenSavedSuccessfully.tr(), isSuccess: true); AppState().requestAllList!.removeAt(AppState().itgWorkListIndex!); if (AppState().requestAllList!.isEmpty) { diff --git a/lib/ui/work_list/worklist_detail_screen.dart b/lib/ui/work_list/worklist_detail_screen.dart index 796acbe..9a9ccee 100644 --- a/lib/ui/work_list/worklist_detail_screen.dart +++ b/lib/ui/work_list/worklist_detail_screen.dart @@ -742,7 +742,7 @@ class _WorkListDetailScreenState extends State { Utils.showLoading(context); GenericResponseModel model = await WorkListApiClient().postNotificationActions(payload); Utils.hideLoading(context); - Utils.showToast(LocaleKeys.yourChangeHasBeenSavedSuccessfully.tr()); + Utils.showToast(LocaleKeys.yourChangeHasBeenSavedSuccessfully.tr(), isSuccess: true); animationIndex = animationIndex + 1; AppState().workList!.removeAt(AppState().workListIndex!); if (AppState().workList!.isEmpty) {