improvements

main_design2.0
Sikander Saleem 2 years ago
parent e8415399ed
commit 0b2ef3d114

@ -48,7 +48,7 @@ class GasRefillCommentsProvider extends ChangeNotifier {
notifyListeners(); notifyListeners();
Response response; Response response;
try { try {
response = await ApiManager.instance.get(URLs.getGazRefillComments + "?callRequestId=$callId"); response = await ApiManager.instance.get(URLs.getGazRefillComments + "?gasRefillId=$callId");
stateCode = response.statusCode; stateCode = response.statusCode;
if (response.statusCode >= 200 && response.statusCode < 300) { if (response.statusCode >= 200 && response.statusCode < 300) {
@ -56,6 +56,9 @@ class GasRefillCommentsProvider extends ChangeNotifier {
List<GasRefillComment> commentsPage = requestsListJson.map((request) => GasRefillComment.fromJson(request)).toList(); List<GasRefillComment> commentsPage = requestsListJson.map((request) => GasRefillComment.fromJson(request)).toList();
comments ??= []; comments ??= [];
comments.addAll(commentsPage); comments.addAll(commentsPage);
comments.sort((a,b) {
return b.createdOn.compareTo(a.createdOn);
});
if (commentsPage.length == pageItemNumber) { if (commentsPage.length == pageItemNumber) {
nextPage = true; nextPage = true;
} else { } else {
@ -79,20 +82,19 @@ class GasRefillCommentsProvider extends ChangeNotifier {
/// return state code if request complete may be 200, 404 or 403 /// return state code if request complete may be 200, 404 or 403
/// for more details check http state manager /// for more details check http state manager
/// lib\controllers\http_status_manger\http_status_manger.dart /// lib\controllers\http_status_manger\http_status_manger.dart
Future<int> addComment(BuildContext context, {@required GasRefillComment comment}) async { Future<int> addComment(BuildContext context, {@required String comment, int id}) async {
if (isLoading == true) return -2; if (isLoading == true) return -2;
isLoading = true; isLoading = true;
Response response; Response response;
try { try {
comment.id = 0;
showDialog(context: context, barrierDismissible: false, builder: (context) => const AppLazyLoading()); 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; stateCode = response.statusCode;
if (response.statusCode >= 200 && response.statusCode < 300) { if (response.statusCode >= 200 && response.statusCode < 300) {
reset(); //visit.status = pentry.ppmVisitStatus; reset(); //visit.status = pentry.ppmVisitStatus;
notifyListeners(); notifyListeners();
Fluttertoast.showToast(msg: context.translation.successfulRequestMessage); Fluttertoast.showToast(msg: context.translation.commentAdded);
Navigator.of(context).pop(); Navigator.of(context).pop();
} else { } else {
Fluttertoast.showToast(msg: "${context.translation.failedToCompleteRequest} ${jsonDecode(response.body)["message"]}"); Fluttertoast.showToast(msg: "${context.translation.failedToCompleteRequest} ${jsonDecode(response.body)["message"]}");

@ -2,6 +2,7 @@
"serverErrorMessage": "الخدمة غير متاحة حاليا", "serverErrorMessage": "الخدمة غير متاحة حاليا",
"failedRequestMessage": "فشل إكمال الطلب", "failedRequestMessage": "فشل إكمال الطلب",
"successfulRequestMessage": "تم إكمال الطلب بنجاح", "successfulRequestMessage": "تم إكمال الطلب بنجاح",
"commentAdded": "تم إضافة التعليق",
"requestLockMessage": "انتظر حتى إكمال الطلب", "requestLockMessage": "انتظر حتى إكمال الطلب",
"cancel": "إلغاء", "cancel": "إلغاء",
"confirm": "تاكيد", "confirm": "تاكيد",

@ -2,6 +2,7 @@
"serverErrorMessage": "Currently, Service not available", "serverErrorMessage": "Currently, Service not available",
"failedRequestMessage": "Failed to complete request", "failedRequestMessage": "Failed to complete request",
"successfulRequestMessage": "Request complete successfully", "successfulRequestMessage": "Request complete successfully",
"commentAdded": "Comment Added",
"requestLockMessage": "Wait until your request complete", "requestLockMessage": "Wait until your request complete",
"cancel": "Cancel", "cancel": "Cancel",
"confirm": "Confirm", "confirm": "Confirm",

@ -165,7 +165,7 @@ class _CreateSubWorkOrderPageState extends State<CreateSubWorkOrderPage> {
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch, crossAxisAlignment: CrossAxisAlignment.stretch,
children: [ children: [
(widget.workOrder?.callRequest?.asset?.site?.name ?? "").heading5(context), (widget.workOrder?.callRequest?.asset?.site?.custName ?? "").heading5(context),
8.height, 8.height,
"${context.translation.assetNo}: ${widget.workOrder?.callRequest?.asset?.assetNumber ?? ""}".bodyText(context), "${context.translation.assetNo}: ${widget.workOrder?.callRequest?.asset?.assetNumber ?? ""}".bodyText(context),
"${context.translation.callId}: ${widget.workOrder?.callRequest?.id}".bodyText(context), "${context.translation.callId}: ${widget.workOrder?.callRequest?.id}".bodyText(context),

@ -39,104 +39,94 @@ class _GasRefillCommentsBottomSheetState extends State<GasRefillCommentsBottomSh
Widget build(BuildContext context) { Widget build(BuildContext context) {
final commentsProvider = Provider.of<GasRefillCommentsProvider>(context); final commentsProvider = Provider.of<GasRefillCommentsProvider>(context);
final userProvider = Provider.of<UserProvider>(context, listen: false); final userProvider = Provider.of<UserProvider>(context, listen: false);
return SingleChildScrollView( return Container(
child: Wrap( height: MediaQuery.of(context).size.height * 0.6,
children: [ clipBehavior: Clip.antiAlias,
Container( margin: EdgeInsets.only(bottom: MediaQuery.of(context).viewInsets.bottom),
clipBehavior: Clip.antiAlias, decoration: BoxDecoration(
margin: EdgeInsets.only(bottom: MediaQuery.of(context).viewInsets.bottom), color: Theme.of(context).scaffoldBackgroundColor,
decoration: BoxDecoration( borderRadius: const BorderRadius.only(topRight: Radius.circular(20), topLeft: Radius.circular(20)),
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), 16.height,
child: Form( Align(
key: _formKey, alignment: AlignmentDirectional.centerStart,
child: Column( child: context.translation.comments.heading3(context).custom(fontWeight: FontWeight.w600),
children: [ ),
LoadingManager( LoadingManager(
isLoading: commentsProvider.isLoading, isLoading: commentsProvider.isLoading,
isFailedLoading: commentsProvider.comments == null, isFailedLoading: commentsProvider.comments == null,
stateCode: commentsProvider.stateCode, stateCode: commentsProvider.stateCode,
onRefresh: () async { onRefresh: () async {
commentsProvider.reset(); commentsProvider.reset();
await commentsProvider.getComments(callId: widget.requestId); await commentsProvider.getComments(callId: widget.requestId);
}, },
child: Column( child: commentsProvider.comments.isEmpty
crossAxisAlignment: CrossAxisAlignment.center, ? SizedBox(
children: [ height: MediaQuery.of(context).size.height * 0.25,
Container( child: NoItemFound(message: context.translation.noDataFound),
width: 40.toScreenWidth, )
height: 5.toScreenHeight, : LazyLoading(
decoration: BoxDecoration(color: AppColor.neutral40, borderRadius: BorderRadius.circular(30)), nextPage: commentsProvider.nextPage,
), onLazyLoad: () async => await commentsProvider.getComments(callId: widget.requestId),
16.height, child: ListView.separated(
Align( itemCount: commentsProvider.comments.length,
alignment: AlignmentDirectional.centerStart, padding: const EdgeInsets.only(top: 16, bottom: 8),
child: context.translation.comments.heading3(context).custom(fontWeight: FontWeight.w600), // shrinkWrap: true,
), // physics: const NeverScrollableScrollPhysics(),
commentsProvider.comments.isEmpty separatorBuilder: (cxt, index) => 8.height,
? SizedBox( itemBuilder: (context, itemIndex) {
height: MediaQuery.of(context).size.height * 0.25, final model = commentsProvider.comments[itemIndex];
child: NoItemFound(message: context.translation.noDataFound), return Column(
) crossAxisAlignment: CrossAxisAlignment.start,
: LazyLoading( children: [
nextPage: commentsProvider.nextPage, (model?.createdBy?.userName ?? "Nurse").heading6(context),
onLazyLoad: () async => await commentsProvider.getComments(callId: widget.requestId), // 8.height,
child: ListView.separated( (model?.comment ?? "").bodyText(context),
itemCount: commentsProvider.comments.length, //8.height,
padding: const EdgeInsets.only(top: 16, bottom: 8), Align(
shrinkWrap: true, alignment: AlignmentDirectional.bottomEnd,
physics: const NeverScrollableScrollPhysics(), child: Text(DateTime.tryParse(model.createdOn).toIso8601String().toServiceRequestDetailsFormat,
separatorBuilder: (cxt, index) => 8.height, style: AppTextStyles.tinyFont.copyWith(color: context.isDark ? AppColor.neutral10 : AppColor.neutral50)),
itemBuilder: (context, itemIndex) { ),
final model = commentsProvider.comments[itemIndex]; ],
return Column( ).toShadowContainer(context);
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, ).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,
), ],
], ),
), ),
); );
} }

@ -1,5 +1,6 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:provider/provider.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/gas_refill_provider.dart';
import 'package:test_sa/controllers/providers/api/user_provider.dart'; import 'package:test_sa/controllers/providers/api/user_provider.dart';
import 'package:test_sa/extensions/context_extension.dart'; import 'package:test_sa/extensions/context_extension.dart';
@ -40,6 +41,7 @@ class _GasRefillDetailsPageState extends State<GasRefillDetailsPage> {
void initState() { void initState() {
// _model.fromGasRefillModel(gasRefillModel); // _model.fromGasRefillModel(gasRefillModel);
super.initState(); super.initState();
Provider.of<GasRefillCommentsProvider>(context, listen: false).reset();
} }
@override @override

Loading…
Cancel
Save