Need some enhancements

pull/2/head
zaid_daoud 3 years ago
parent 08841c7859
commit d470a19bef

@ -142,7 +142,6 @@ class GasRefillProvider extends ChangeNotifier {
@required GasRefillModel oldModel,
@required GasRefillModel newModel,
}) async {
print("${oldModel?.id} assigned EEEEE ${oldModel?.assignedEmployee?.toJson()}");
Map<String, dynamic> body = {
"id": newModel.id,
"gazRefillNo": newModel.title ?? "",

@ -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() {

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

@ -289,168 +289,176 @@ class _RequestGasRefillState extends State<RequestGasRefill> {
],
),
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<RequestGasRefill> {
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(() {});
},
);

@ -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(),
],
);

Loading…
Cancel
Save