From d470a19befa10e857e6520323115306dc8c3e8a9 Mon Sep 17 00:00:00 2001 From: zaid_daoud Date: Tue, 13 Jun 2023 14:37:52 +0300 Subject: [PATCH] Need some enhancements --- .../providers/api/gas_refill_provider.dart | 1 - lib/models/gas_refill/gas_refill_details.dart | 2 + lib/models/gas_refill/gas_refill_model.dart | 1 - .../user/gas_refill/request_gas_refill.dart | 322 +++++++++--------- .../gas_refill_create_details_item.dart | 43 ++- 5 files changed, 210 insertions(+), 159 deletions(-) diff --git a/lib/controllers/providers/api/gas_refill_provider.dart b/lib/controllers/providers/api/gas_refill_provider.dart index cbd66b55..33c9fd61 100644 --- a/lib/controllers/providers/api/gas_refill_provider.dart +++ b/lib/controllers/providers/api/gas_refill_provider.dart @@ -142,7 +142,6 @@ class GasRefillProvider extends ChangeNotifier { @required GasRefillModel oldModel, @required GasRefillModel newModel, }) async { - print("${oldModel?.id} assigned EEEEE ${oldModel?.assignedEmployee?.toJson()}"); Map body = { "id": newModel.id, "gazRefillNo": newModel.title ?? "", diff --git a/lib/models/gas_refill/gas_refill_details.dart b/lib/models/gas_refill/gas_refill_details.dart index 02d31cf4..0c9afe0e 100644 --- a/lib/models/gas_refill/gas_refill_details.dart +++ b/lib/models/gas_refill/gas_refill_details.dart @@ -6,6 +6,7 @@ class GasRefillDetails { Lookup cylinderType; double requestedQuantity; double deliveredQuantity; + bool selectedForEditing; GasRefillDetails({ this.type, @@ -13,6 +14,7 @@ class GasRefillDetails { this.cylinderType, this.requestedQuantity, this.deliveredQuantity, + this.selectedForEditing, }); bool validate() { diff --git a/lib/models/gas_refill/gas_refill_model.dart b/lib/models/gas_refill/gas_refill_model.dart index ad2ebde2..13a6e6b8 100644 --- a/lib/models/gas_refill/gas_refill_model.dart +++ b/lib/models/gas_refill/gas_refill_model.dart @@ -66,7 +66,6 @@ class GasRefillModel { List list = parsedJson["gazRefillDetails"]; details = list.map((e) => GasRefillDetails.fromJson(e)).toList(); } - print("${parsedJson['assignedEmployee']}ddddd"); return GasRefillModel( id: parsedJson["id"], //userId: parsedJson["uid"], diff --git a/lib/views/pages/user/gas_refill/request_gas_refill.dart b/lib/views/pages/user/gas_refill/request_gas_refill.dart index da419033..7b745daa 100644 --- a/lib/views/pages/user/gas_refill/request_gas_refill.dart +++ b/lib/views/pages/user/gas_refill/request_gas_refill.dart @@ -289,168 +289,176 @@ class _RequestGasRefillState extends State { ], ), if (_userProvider.user?.type == UsersTypes.engineer) - Row( + Column( children: [ - Expanded( - child: Column( - crossAxisAlignment: CrossAxisAlignment.stretch, - children: [ - const ASubTitle("Start of Work"), - SizedBox( - height: 8 * AppStyle.getScaleFactor(context), + Row( + children: [ + Expanded( + child: Column( + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ + const ASubTitle("Start of Work"), + SizedBox( + height: 8 * AppStyle.getScaleFactor(context), + ), + ADateTimePicker( + date: _gasRefillProvider.startDate, + from: DateTime.now().subtract(const Duration(days: 365)), + to: DateTime.now().add(const Duration(days: 365)), + onDateTimePicker: (date) { + _gasRefillProvider.startDate = date; + setState(() {}); + }, + ), + ], ), - ADateTimePicker( - date: _gasRefillProvider.startDate, - from: DateTime.now().subtract(const Duration(days: 365)), - to: DateTime.now().add(const Duration(days: 365)), - onDateTimePicker: (date) { - _gasRefillProvider.startDate = date; - setState(() {}); - }, + ), + const SizedBox(width: 8), + Expanded( + child: Column( + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ + const ASubTitle("End of Work"), + SizedBox( + height: 8 * AppStyle.getScaleFactor(context), + ), + ADateTimePicker( + date: _gasRefillProvider.endDate, + from: DateTime.now().subtract(const Duration(days: 365)), + to: DateTime.now().add(const Duration(days: 365)), + onDateTimePicker: (date) { + _gasRefillProvider.endDate = date; + setState(() {}); + }, + ), + ], ), - ], + ), + ], + ), + const SizedBox(height: 8), + ASubTitle(_subtitle.workingHours), + const SizedBox(height: 4), + ATextFormField( + initialValue: null, + textAlign: TextAlign.center, + hintText: _gasRefillProvider.startDate == null + ? "0" + : ((_gasRefillProvider.endDate?.difference(_gasRefillProvider.startDate)?.inMinutes ?? 0) / 60)?.toStringAsFixed(2)?.toString() ?? "0", + enable: false, + style: Theme.of(context).textTheme.subtitle1, + validator: (value) => Validator.isNumeric(value) ? null : _subtitle.requiredWord, + textInputType: TextInputType.number, + onSaved: (value) { + // _serviceReport.workHours = value; + }, + ), + ], + ), + if (widget.gasRefillModel == null) + Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + const SizedBox(height: 8), + Divider(color: Theme.of(context).colorScheme.primary), + const SizedBox(height: 4), + const ASubTitle("Type"), + if (_validate && _currentDetails.type == null) ASubTitle(_subtitle.requiredWord, color: Colors.red), + const SizedBox(height: 4), + GasTypeMenu( + initialValue: _currentDetails.type, + onSelect: (status) { + _currentDetails.type = status; + }, + ), + const SizedBox(height: 8), + const ASubTitle("Cylinder Size"), + if (_validate && _currentDetails.cylinderSize == null) + ASubTitle( + _subtitle.requiredWord, + color: Colors.red, ), + const SizedBox( + height: 4, ), - const SizedBox(width: 8), - Expanded( - child: Column( - crossAxisAlignment: CrossAxisAlignment.stretch, - children: [ - const ASubTitle("End of Work"), - SizedBox( - height: 8 * AppStyle.getScaleFactor(context), - ), - ADateTimePicker( - date: _gasRefillProvider.endDate, - from: DateTime.now().subtract(const Duration(days: 365)), - to: DateTime.now().add(const Duration(days: 365)), - onDateTimePicker: (date) { - _gasRefillProvider.endDate = date; - setState(() {}); - }, - ), - ], + GasCylinderSizeMenu( + initialValue: _currentDetails.cylinderSize, + onSelect: (status) { + _currentDetails.cylinderSize = status; + }, + ), + const SizedBox( + height: 8, + ), + const SizedBox( + height: 8, + ), + const ASubTitle("Cylinder Type"), + if (_validate && _currentDetails.cylinderSize == null) + ASubTitle( + _subtitle.requiredWord, + color: Colors.red, + ), + const SizedBox( + height: 4, + ), + GasCylinderTypesMenu( + initialValue: _currentDetails.cylinderType, + onSelect: (status) { + _currentDetails.cylinderType = status; + }, + ), + const SizedBox( + height: 8, + ), + ASubTitle(_subtitle.requestedQuantity), + if (_validate && _currentDetails?.requestedQuantity == null) + ASubTitle( + _subtitle.requiredWord, + color: Colors.red, + ), + SizedBox( + height: 4, + ), + ATextFormField( + initialValue: (_currentDetails?.requestedQuantity ?? "").toString(), + textAlign: TextAlign.center, + controller: _requestedQuantityController, + style: Theme.of(context).textTheme.subtitle1, + validator: (value) => Validator.isNumeric(value) ? null : "allow numbers only", + textInputType: TextInputType.number, + onChange: (value) { + _currentDetails?.requestedQuantity = double.tryParse(value); + }, + ), + if (widget.gasRefillModel != null) const SizedBox(height: 16), + if (widget.gasRefillModel != null) ASubTitle(_subtitle.deliveredQuantity), + if (widget.gasRefillModel != null && _validate && _currentDetails?.deliveredQuantity == null) + ASubTitle( + _subtitle.requiredWord, + color: Colors.red, + ), + if (widget.gasRefillModel != null) const SizedBox(height: 4), + if (widget.gasRefillModel != null) + ATextFormField( + initialValue: (_currentDetails?.deliveredQuantity ?? "").toString(), + textAlign: TextAlign.center, + controller: _deliveredQuantityController, + style: Theme.of(context).textTheme.subtitle1, + validator: (value) => Validator.isNumeric(value) ? null : "allow numbers only", + textInputType: TextInputType.number, + onChange: (value) { + _currentDetails?.deliveredQuantity = double.tryParse(value); + }, ), + const SizedBox(height: 16), + AButton( + text: _subtitle.add, + onPressed: _addNewModel, ), ], ), - if (_userProvider.user?.type == UsersTypes.engineer) const SizedBox(height: 8), - if (_userProvider.user?.type == UsersTypes.engineer) ASubTitle(_subtitle.workingHours), - if (_userProvider.user?.type == UsersTypes.engineer) const SizedBox(height: 4), - if (_userProvider.user?.type == UsersTypes.engineer) - ATextFormField( - initialValue: null, - textAlign: TextAlign.center, - hintText: _gasRefillProvider.startDate == null - ? "0" - : ((_gasRefillProvider.endDate?.difference(_gasRefillProvider.startDate)?.inMinutes ?? 0) / 60)?.toStringAsFixed(2)?.toString() ?? "0", - enable: false, - style: Theme.of(context).textTheme.subtitle1, - validator: (value) => Validator.isNumeric(value) ? null : _subtitle.requiredWord, - textInputType: TextInputType.number, - onSaved: (value) { - // _serviceReport.workHours = value; - }, - ), - const SizedBox(height: 8), - Divider(color: Theme.of(context).colorScheme.primary), - const SizedBox(height: 4), - const ASubTitle("Type"), - if (_validate && _currentDetails.type == null) ASubTitle(_subtitle.requiredWord, color: Colors.red), - const SizedBox(height: 4), - GasTypeMenu( - initialValue: _currentDetails.type, - onSelect: (status) { - _currentDetails.type = status; - }, - ), - const SizedBox(height: 8), - const ASubTitle("Cylinder Size"), - if (_validate && _currentDetails.cylinderSize == null) - ASubTitle( - _subtitle.requiredWord, - color: Colors.red, - ), - const SizedBox( - height: 4, - ), - GasCylinderSizeMenu( - initialValue: _currentDetails.cylinderSize, - onSelect: (status) { - _currentDetails.cylinderSize = status; - }, - ), - const SizedBox( - height: 8, - ), - - const SizedBox( - height: 8, - ), - const ASubTitle("Cylinder Type"), - if (_validate && _currentDetails.cylinderSize == null) - ASubTitle( - _subtitle.requiredWord, - color: Colors.red, - ), - const SizedBox( - height: 4, - ), - GasCylinderTypesMenu( - initialValue: _currentDetails.cylinderType, - onSelect: (status) { - _currentDetails.cylinderType = status; - }, - ), - const SizedBox( - height: 8, - ), - ASubTitle(_subtitle.requestedQuantity), - if (_validate && _currentDetails?.requestedQuantity == null) - ASubTitle( - _subtitle.requiredWord, - color: Colors.red, - ), - SizedBox( - height: 4, - ), - ATextFormField( - initialValue: (_currentDetails?.requestedQuantity ?? "").toString(), - textAlign: TextAlign.center, - controller: _requestedQuantityController, - style: Theme.of(context).textTheme.subtitle1, - validator: (value) => Validator.isNumeric(value) ? null : "allow numbers only", - textInputType: TextInputType.number, - onChange: (value) { - _currentDetails?.requestedQuantity = double.tryParse(value); - }, - ), - if (widget.gasRefillModel != null) const SizedBox(height: 16), - if (widget.gasRefillModel != null) ASubTitle(_subtitle.deliveredQuantity), - if (widget.gasRefillModel != null && _validate && _currentDetails?.deliveredQuantity == null) - ASubTitle( - _subtitle.requiredWord, - color: Colors.red, - ), - if (widget.gasRefillModel != null) const SizedBox(height: 4), - if (widget.gasRefillModel != null) - ATextFormField( - initialValue: (_currentDetails?.deliveredQuantity ?? "").toString(), - textAlign: TextAlign.center, - controller: _deliveredQuantityController, - style: Theme.of(context).textTheme.subtitle1, - validator: (value) => Validator.isNumeric(value) ? null : "allow numbers only", - textInputType: TextInputType.number, - onChange: (value) { - _currentDetails?.deliveredQuantity = double.tryParse(value); - }, - ), const SizedBox(height: 16), - AButton( - text: _subtitle.add, - onPressed: _addNewModel, - ), - if (_formModel.details.isNotEmpty) const ASubTitle("Gas Requests"), ListView.builder( key: _DetailsKey, @@ -460,9 +468,15 @@ class _RequestGasRefillState extends State { itemBuilder: (context, index) { final model = _formModel.details[index]; return GasRefillCreateDetailsItem( + isUpdate: widget.gasRefillModel != null, model: model, - onDelete: () { - _formModel.details.remove(model); + onPressed: () { + if (widget.gasRefillModel != null) { + model.selectedForEditing = !(model.selectedForEditing ?? false); + } + if (widget.gasRefillModel == null) { + _formModel.details.remove(model); + } setState(() {}); }, ); diff --git a/lib/views/widgets/gas_refill/gas_refill_create_details_item.dart b/lib/views/widgets/gas_refill/gas_refill_create_details_item.dart index 8fef555f..317f7c2b 100644 --- a/lib/views/widgets/gas_refill/gas_refill_create_details_item.dart +++ b/lib/views/widgets/gas_refill/gas_refill_create_details_item.dart @@ -1,20 +1,29 @@ import 'package:flutter/material.dart'; import 'package:test_sa/models/gas_refill/gas_refill_details.dart'; import 'package:test_sa/views/app_style/colors.dart'; +import 'package:test_sa/views/widgets/app_text_form_field.dart'; + +import '../../../controllers/localization/localization.dart'; +import '../buttons/app_button.dart'; +import '../titles/app_sub_title.dart'; class GasRefillCreateDetailsItem extends StatelessWidget { final GasRefillDetails model; - final VoidCallback onDelete; + final VoidCallback onPressed; + final bool isUpdate; - const GasRefillCreateDetailsItem({Key key, this.model, this.onDelete}) : super(key: key); + const GasRefillCreateDetailsItem({Key key, this.isUpdate, this.model, this.onPressed}) : super(key: key); @override Widget build(BuildContext context) { + final subtitle = AppLocalization.of(context).subtitle; + final startEditing = isUpdate && (model.selectedForEditing ?? false); + String deliveredQuantity = "0"; return Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Row( - children: [Expanded(child: Text(model.type.name)), IconButton(onPressed: onDelete, color: AColors.red, icon: const Icon(Icons.delete))], + children: [Expanded(child: Text(model.type.name)), IconButton(onPressed: onPressed, color: isUpdate ? AColors.cyan : AColors.red, icon: Icon(isUpdate ? Icons.edit : Icons.delete))], ), Wrap( spacing: 10, @@ -31,6 +40,34 @@ class GasRefillCreateDetailsItem extends StatelessWidget { Text(model.deliveredQuantity.toStringAsFixed(0)), ], ), + if (startEditing) const SizedBox(height: 16), + if (startEditing) ASubTitle(subtitle.deliveredQuantity), + if (startEditing) const SizedBox(height: 4), + if (startEditing) + ATextFormField( + initialValue: model.deliveredQuantity?.toString(), + textAlign: TextAlign.center, + // controller: deliveredQuantityController, + style: Theme.of(context).textTheme.subtitle1, + // validator: (value) => Validator.isNumeric(value) ? null : "allow numbers only", + textInputType: TextInputType.number, + onChange: (value) { + deliveredQuantity = value; + // _currentDetails?.deliveredQuantity = double.tryParse(value); + }, + ), + if (startEditing) const SizedBox(height: 8), + if (startEditing) + AButton( + text: subtitle.edit, + onPressed: () { + final value = double.tryParse(deliveredQuantity ?? ""); + if (value != null) { + model.deliveredQuantity = value; + onPressed(); + } + }, + ), const Divider(), ], );