improvements

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

@ -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<GasRefillComment> 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<int> addComment(BuildContext context, {@required GasRefillComment comment}) async {
Future<int> 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"]}");

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

@ -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",

@ -165,7 +165,7 @@ class _CreateSubWorkOrderPageState extends State<CreateSubWorkOrderPage> {
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),

@ -39,104 +39,94 @@ class _GasRefillCommentsBottomSheetState extends State<GasRefillCommentsBottomSh
Widget build(BuildContext context) {
final commentsProvider = Provider.of<GasRefillCommentsProvider>(context);
final userProvider = Provider.of<UserProvider>(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,
],
),
),
);
}

@ -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<GasRefillDetailsPage> {
void initState() {
// _model.fromGasRefillModel(gasRefillModel);
super.initState();
Provider.of<GasRefillCommentsProvider>(context, listen: false).reset();
}
@override

Loading…
Cancel
Save