From 0b2ef3d11462c234e37e30a89cb1196a441fc66a Mon Sep 17 00:00:00 2001 From: Sikander Saleem Date: Sun, 14 Jan 2024 15:01:31 +0300 Subject: [PATCH] improvements --- .../providers/api/gas_refill_comments.dart | 12 +- lib/l10n/app_ar.arb | 1 + lib/l10n/app_en.arb | 1 + .../create_sub_workorder_page.dart | 2 +- .../user/gas_refill/gas_refill_comments.dart | 180 +++++++++--------- .../user/gas_refill/gas_refill_details.dart | 2 + 6 files changed, 97 insertions(+), 101 deletions(-) diff --git a/lib/controllers/providers/api/gas_refill_comments.dart b/lib/controllers/providers/api/gas_refill_comments.dart index 9a06013e..0c7ab63b 100644 --- a/lib/controllers/providers/api/gas_refill_comments.dart +++ b/lib/controllers/providers/api/gas_refill_comments.dart @@ -48,7 +48,7 @@ class GasRefillCommentsProvider extends ChangeNotifier { notifyListeners(); Response response; try { - response = await ApiManager.instance.get(URLs.getGazRefillComments + "?callRequestId=$callId"); + response = await ApiManager.instance.get(URLs.getGazRefillComments + "?gasRefillId=$callId"); stateCode = response.statusCode; if (response.statusCode >= 200 && response.statusCode < 300) { @@ -56,6 +56,9 @@ class GasRefillCommentsProvider extends ChangeNotifier { List commentsPage = requestsListJson.map((request) => GasRefillComment.fromJson(request)).toList(); comments ??= []; comments.addAll(commentsPage); + comments.sort((a,b) { + return b.createdOn.compareTo(a.createdOn); + }); if (commentsPage.length == pageItemNumber) { nextPage = true; } else { @@ -79,20 +82,19 @@ class GasRefillCommentsProvider extends ChangeNotifier { /// return state code if request complete may be 200, 404 or 403 /// for more details check http state manager /// lib\controllers\http_status_manger\http_status_manger.dart - Future addComment(BuildContext context, {@required GasRefillComment comment}) async { + Future addComment(BuildContext context, {@required String comment, int id}) async { if (isLoading == true) return -2; isLoading = true; Response response; try { - comment.id = 0; showDialog(context: context, barrierDismissible: false, builder: (context) => const AppLazyLoading()); - response = await ApiManager.instance.post(URLs.addGazRefillComment, body: comment.toJson()); + response = await ApiManager.instance.post(URLs.addGazRefillComment, body: {"id": 0, "gasRefillId": id, "comment": comment}); stateCode = response.statusCode; if (response.statusCode >= 200 && response.statusCode < 300) { reset(); //visit.status = pentry.ppmVisitStatus; notifyListeners(); - Fluttertoast.showToast(msg: context.translation.successfulRequestMessage); + Fluttertoast.showToast(msg: context.translation.commentAdded); Navigator.of(context).pop(); } else { Fluttertoast.showToast(msg: "${context.translation.failedToCompleteRequest} ${jsonDecode(response.body)["message"]}"); diff --git a/lib/l10n/app_ar.arb b/lib/l10n/app_ar.arb index 77796efb..6e67aef1 100644 --- a/lib/l10n/app_ar.arb +++ b/lib/l10n/app_ar.arb @@ -2,6 +2,7 @@ "serverErrorMessage": "الخدمة غير متاحة حاليا", "failedRequestMessage": "فشل إكمال الطلب", "successfulRequestMessage": "تم إكمال الطلب بنجاح", + "commentAdded": "تم إضافة التعليق", "requestLockMessage": "انتظر حتى إكمال الطلب", "cancel": "إلغاء", "confirm": "تاكيد", diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb index c1fcaac2..7a7dbb54 100644 --- a/lib/l10n/app_en.arb +++ b/lib/l10n/app_en.arb @@ -2,6 +2,7 @@ "serverErrorMessage": "Currently, Service not available", "failedRequestMessage": "Failed to complete request", "successfulRequestMessage": "Request complete successfully", + "commentAdded": "Comment Added", "requestLockMessage": "Wait until your request complete", "cancel": "Cancel", "confirm": "Confirm", diff --git a/lib/views/pages/sub_workorder/create_sub_workorder_page.dart b/lib/views/pages/sub_workorder/create_sub_workorder_page.dart index 87b170de..8612bd8b 100644 --- a/lib/views/pages/sub_workorder/create_sub_workorder_page.dart +++ b/lib/views/pages/sub_workorder/create_sub_workorder_page.dart @@ -165,7 +165,7 @@ class _CreateSubWorkOrderPageState extends State { child: Column( crossAxisAlignment: CrossAxisAlignment.stretch, children: [ - (widget.workOrder?.callRequest?.asset?.site?.name ?? "").heading5(context), + (widget.workOrder?.callRequest?.asset?.site?.custName ?? "").heading5(context), 8.height, "${context.translation.assetNo}: ${widget.workOrder?.callRequest?.asset?.assetNumber ?? ""}".bodyText(context), "${context.translation.callId}: ${widget.workOrder?.callRequest?.id}".bodyText(context), diff --git a/lib/views/pages/user/gas_refill/gas_refill_comments.dart b/lib/views/pages/user/gas_refill/gas_refill_comments.dart index fa45981e..f19b21d2 100644 --- a/lib/views/pages/user/gas_refill/gas_refill_comments.dart +++ b/lib/views/pages/user/gas_refill/gas_refill_comments.dart @@ -39,104 +39,94 @@ class _GasRefillCommentsBottomSheetState extends State(context); final userProvider = Provider.of(context, listen: false); - return SingleChildScrollView( - child: Wrap( - children: [ - Container( - clipBehavior: Clip.antiAlias, - margin: EdgeInsets.only(bottom: MediaQuery.of(context).viewInsets.bottom), - decoration: BoxDecoration( - color: Theme.of(context).scaffoldBackgroundColor, - borderRadius: const BorderRadius.only(topRight: Radius.circular(20), topLeft: Radius.circular(20)), + return Container( + height: MediaQuery.of(context).size.height * 0.6, + clipBehavior: Clip.antiAlias, + margin: EdgeInsets.only(bottom: MediaQuery.of(context).viewInsets.bottom), + decoration: BoxDecoration( + color: Theme.of(context).scaffoldBackgroundColor, + borderRadius: const BorderRadius.only(topRight: Radius.circular(20), topLeft: Radius.circular(20)), + ), + padding: EdgeInsets.symmetric(horizontal: 16.toScreenWidth, vertical: 8.toScreenHeight), + child: Form( + key: _formKey, + child: Column( + children: [ + Container( + width: 40.toScreenWidth, + height: 5.toScreenHeight, + decoration: BoxDecoration(color: AppColor.neutral40, borderRadius: BorderRadius.circular(30)), ), - padding: EdgeInsets.symmetric(horizontal: 16.toScreenWidth, vertical: 8.toScreenHeight), - child: Form( - key: _formKey, - child: Column( - children: [ - LoadingManager( - isLoading: commentsProvider.isLoading, - isFailedLoading: commentsProvider.comments == null, - stateCode: commentsProvider.stateCode, - onRefresh: () async { - commentsProvider.reset(); - await commentsProvider.getComments(callId: widget.requestId); - }, - child: Column( - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - Container( - width: 40.toScreenWidth, - height: 5.toScreenHeight, - decoration: BoxDecoration(color: AppColor.neutral40, borderRadius: BorderRadius.circular(30)), - ), - 16.height, - Align( - alignment: AlignmentDirectional.centerStart, - child: context.translation.comments.heading3(context).custom(fontWeight: FontWeight.w600), - ), - commentsProvider.comments.isEmpty - ? SizedBox( - height: MediaQuery.of(context).size.height * 0.25, - child: NoItemFound(message: context.translation.noDataFound), - ) - : LazyLoading( - nextPage: commentsProvider.nextPage, - onLazyLoad: () async => await commentsProvider.getComments(callId: widget.requestId), - child: ListView.separated( - itemCount: commentsProvider.comments.length, - padding: const EdgeInsets.only(top: 16, bottom: 8), - shrinkWrap: true, - physics: const NeverScrollableScrollPhysics(), - separatorBuilder: (cxt, index) => 8.height, - itemBuilder: (context, itemIndex) { - final model = commentsProvider.comments[itemIndex]; - return Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - (model?.createdBy?.userName ?? "Nurse").heading6(context), - 8.height, - (model?.comment ?? "").bodyText(context), - 8.height, - Align( - alignment: AlignmentDirectional.bottomEnd, - child: Text(DateTime.tryParse(model.createdOn).toIso8601String().toServiceRequestDetailsFormat, - style: AppTextStyles.tinyFont.copyWith(color: context.isDark ? AppColor.neutral10 : AppColor.neutral50)), - ), - ], - ).toShadowContainer(context); - }, - ), - ), - ], - ), - ), - if (userProvider.user.type == UsersTypes.normal_user) 8.height, - if (userProvider.user.type == UsersTypes.normal_user) - AppTextFormField( - labelText: "Type any comment", - backgroundColor: AppColor.neutral30, - alignLabelWithHint: true, - showShadow: false, - validator: (value) => Validator.hasValue(value) ? null : context.translation.requiredField, - textInputType: TextInputType.multiline, - suffixIcon: "comment_send".toSvgAsset().paddingOnly(end: 16).onPress(() { - if (_formKey.currentState.validate()) { - _formKey.currentState.save(); - final comment = GasRefillComment(id: 0, gasRefillId: num.tryParse(widget.requestId ?? ""), comment: text); - commentsProvider.addComment(context, comment: comment); - } - }), - onSaved: (value) { - text = value; - }, + 16.height, + Align( + alignment: AlignmentDirectional.centerStart, + child: context.translation.comments.heading3(context).custom(fontWeight: FontWeight.w600), + ), + LoadingManager( + isLoading: commentsProvider.isLoading, + isFailedLoading: commentsProvider.comments == null, + stateCode: commentsProvider.stateCode, + onRefresh: () async { + commentsProvider.reset(); + await commentsProvider.getComments(callId: widget.requestId); + }, + child: commentsProvider.comments.isEmpty + ? SizedBox( + height: MediaQuery.of(context).size.height * 0.25, + child: NoItemFound(message: context.translation.noDataFound), + ) + : LazyLoading( + nextPage: commentsProvider.nextPage, + onLazyLoad: () async => await commentsProvider.getComments(callId: widget.requestId), + child: ListView.separated( + itemCount: commentsProvider.comments.length, + padding: const EdgeInsets.only(top: 16, bottom: 8), + // shrinkWrap: true, + // physics: const NeverScrollableScrollPhysics(), + separatorBuilder: (cxt, index) => 8.height, + itemBuilder: (context, itemIndex) { + final model = commentsProvider.comments[itemIndex]; + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + (model?.createdBy?.userName ?? "Nurse").heading6(context), + // 8.height, + (model?.comment ?? "").bodyText(context), + //8.height, + Align( + alignment: AlignmentDirectional.bottomEnd, + child: Text(DateTime.tryParse(model.createdOn).toIso8601String().toServiceRequestDetailsFormat, + style: AppTextStyles.tinyFont.copyWith(color: context.isDark ? AppColor.neutral10 : AppColor.neutral50)), + ), + ], + ).toShadowContainer(context); + }, + ), ), - 16.height, - ], + ).expanded, + if (userProvider.user.type == UsersTypes.normal_user) 8.height, + if (userProvider.user.type == UsersTypes.normal_user) + AppTextFormField( + labelText: "Type any comment", + backgroundColor: AppColor.neutral30, + alignLabelWithHint: true, + showShadow: false, + validator: (value) => Validator.hasValue(value) ? null : context.translation.requiredField, + textInputType: TextInputType.multiline, + suffixIcon: "comment_send".toSvgAsset().paddingOnly(end: 16).onPress(() { + if (_formKey.currentState.validate()) { + _formKey.currentState.save(); + // final comment = GasRefillComment(id: 0, gasRefillId: num.tryParse(widget.requestId ?? ""), comment: text); + commentsProvider.addComment(context, comment: text, id: num.tryParse(widget.requestId ?? "")); + } + }), + onSaved: (value) { + text = value; + }, ), - ), - ), - ], + 16.height, + ], + ), ), ); } diff --git a/lib/views/pages/user/gas_refill/gas_refill_details.dart b/lib/views/pages/user/gas_refill/gas_refill_details.dart index 6fee2bec..94b0308a 100644 --- a/lib/views/pages/user/gas_refill/gas_refill_details.dart +++ b/lib/views/pages/user/gas_refill/gas_refill_details.dart @@ -1,5 +1,6 @@ import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; +import 'package:test_sa/controllers/providers/api/gas_refill_comments.dart'; import 'package:test_sa/controllers/providers/api/gas_refill_provider.dart'; import 'package:test_sa/controllers/providers/api/user_provider.dart'; import 'package:test_sa/extensions/context_extension.dart'; @@ -40,6 +41,7 @@ class _GasRefillDetailsPageState extends State { void initState() { // _model.fromGasRefillModel(gasRefillModel); super.initState(); + Provider.of(context, listen: false).reset(); } @override