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 oldModel,
@required GasRefillModel newModel, @required GasRefillModel newModel,
}) async { }) async {
print("${oldModel?.id} assigned EEEEE ${oldModel?.assignedEmployee?.toJson()}");
Map<String, dynamic> body = { Map<String, dynamic> body = {
"id": newModel.id, "id": newModel.id,
"gazRefillNo": newModel.title ?? "", "gazRefillNo": newModel.title ?? "",

@ -6,6 +6,7 @@ class GasRefillDetails {
Lookup cylinderType; Lookup cylinderType;
double requestedQuantity; double requestedQuantity;
double deliveredQuantity; double deliveredQuantity;
bool selectedForEditing;
GasRefillDetails({ GasRefillDetails({
this.type, this.type,
@ -13,6 +14,7 @@ class GasRefillDetails {
this.cylinderType, this.cylinderType,
this.requestedQuantity, this.requestedQuantity,
this.deliveredQuantity, this.deliveredQuantity,
this.selectedForEditing,
}); });
bool validate() { bool validate() {

@ -66,7 +66,6 @@ class GasRefillModel {
List list = parsedJson["gazRefillDetails"]; List list = parsedJson["gazRefillDetails"];
details = list.map((e) => GasRefillDetails.fromJson(e)).toList(); details = list.map((e) => GasRefillDetails.fromJson(e)).toList();
} }
print("${parsedJson['assignedEmployee']}ddddd");
return GasRefillModel( return GasRefillModel(
id: parsedJson["id"], id: parsedJson["id"],
//userId: parsedJson["uid"], //userId: parsedJson["uid"],

@ -289,6 +289,8 @@ class _RequestGasRefillState extends State<RequestGasRefill> {
], ],
), ),
if (_userProvider.user?.type == UsersTypes.engineer) if (_userProvider.user?.type == UsersTypes.engineer)
Column(
children: [
Row( Row(
children: [ children: [
Expanded( Expanded(
@ -334,10 +336,9 @@ class _RequestGasRefillState extends State<RequestGasRefill> {
), ),
], ],
), ),
if (_userProvider.user?.type == UsersTypes.engineer) const SizedBox(height: 8), const SizedBox(height: 8),
if (_userProvider.user?.type == UsersTypes.engineer) ASubTitle(_subtitle.workingHours), ASubTitle(_subtitle.workingHours),
if (_userProvider.user?.type == UsersTypes.engineer) const SizedBox(height: 4), const SizedBox(height: 4),
if (_userProvider.user?.type == UsersTypes.engineer)
ATextFormField( ATextFormField(
initialValue: null, initialValue: null,
textAlign: TextAlign.center, textAlign: TextAlign.center,
@ -352,6 +353,12 @@ class _RequestGasRefillState extends State<RequestGasRefill> {
// _serviceReport.workHours = value; // _serviceReport.workHours = value;
}, },
), ),
],
),
if (widget.gasRefillModel == null)
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const SizedBox(height: 8), const SizedBox(height: 8),
Divider(color: Theme.of(context).colorScheme.primary), Divider(color: Theme.of(context).colorScheme.primary),
const SizedBox(height: 4), const SizedBox(height: 4),
@ -383,7 +390,6 @@ class _RequestGasRefillState extends State<RequestGasRefill> {
const SizedBox( const SizedBox(
height: 8, height: 8,
), ),
const SizedBox( const SizedBox(
height: 8, height: 8,
), ),
@ -450,7 +456,9 @@ class _RequestGasRefillState extends State<RequestGasRefill> {
text: _subtitle.add, text: _subtitle.add,
onPressed: _addNewModel, onPressed: _addNewModel,
), ),
],
),
const SizedBox(height: 16),
if (_formModel.details.isNotEmpty) const ASubTitle("Gas Requests"), if (_formModel.details.isNotEmpty) const ASubTitle("Gas Requests"),
ListView.builder( ListView.builder(
key: _DetailsKey, key: _DetailsKey,
@ -460,9 +468,15 @@ class _RequestGasRefillState extends State<RequestGasRefill> {
itemBuilder: (context, index) { itemBuilder: (context, index) {
final model = _formModel.details[index]; final model = _formModel.details[index];
return GasRefillCreateDetailsItem( return GasRefillCreateDetailsItem(
isUpdate: widget.gasRefillModel != null,
model: model, model: model,
onDelete: () { onPressed: () {
if (widget.gasRefillModel != null) {
model.selectedForEditing = !(model.selectedForEditing ?? false);
}
if (widget.gasRefillModel == null) {
_formModel.details.remove(model); _formModel.details.remove(model);
}
setState(() {}); setState(() {});
}, },
); );

@ -1,20 +1,29 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:test_sa/models/gas_refill/gas_refill_details.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/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 { class GasRefillCreateDetailsItem extends StatelessWidget {
final GasRefillDetails model; 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 @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final subtitle = AppLocalization.of(context).subtitle;
final startEditing = isUpdate && (model.selectedForEditing ?? false);
String deliveredQuantity = "0";
return Column( return Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
Row( 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( Wrap(
spacing: 10, spacing: 10,
@ -31,6 +40,34 @@ class GasRefillCreateDetailsItem extends StatelessWidget {
Text(model.deliveredQuantity.toStringAsFixed(0)), 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(), const Divider(),
], ],
); );

Loading…
Cancel
Save