|
|
|
|
@ -7,83 +7,86 @@ import '../../../controllers/localization/localization.dart';
|
|
|
|
|
import '../buttons/app_button.dart';
|
|
|
|
|
import '../titles/app_sub_title.dart';
|
|
|
|
|
|
|
|
|
|
class GasRefillCreateDetailsItem extends StatelessWidget {
|
|
|
|
|
GasRefillDetails model;
|
|
|
|
|
class GasRefillCreateDetailsItem extends StatefulWidget {
|
|
|
|
|
final GasRefillDetails model;
|
|
|
|
|
final VoidCallback onPressed;
|
|
|
|
|
final bool isUpdate;
|
|
|
|
|
|
|
|
|
|
GasRefillCreateDetailsItem({Key key, this.isUpdate, this.model, this.onPressed}) : super(key: key);
|
|
|
|
|
const GasRefillCreateDetailsItem({Key key, this.isUpdate, this.model, this.onPressed}) : super(key: key);
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
State<GasRefillCreateDetailsItem> createState() => _GasRefillCreateDetailsItemState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _GasRefillCreateDetailsItemState extends State<GasRefillCreateDetailsItem> {
|
|
|
|
|
GlobalKey<FormState> _formKey;
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
super.initState();
|
|
|
|
|
_formKey = GlobalKey<FormState>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
final subtitle = AppLocalization.of(context).subtitle;
|
|
|
|
|
final startEditing = isUpdate && (model.selectedForEditing ?? false);
|
|
|
|
|
double deliveredQuantity;
|
|
|
|
|
return Column(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
children: [
|
|
|
|
|
Row(
|
|
|
|
|
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,
|
|
|
|
|
children: [
|
|
|
|
|
Text("Quantity: ${model.requestedQuantity.toStringAsFixed(0)}"),
|
|
|
|
|
Text("Cylinder Size: ${model.cylinderSize.name}"),
|
|
|
|
|
Text("Cylinder Type: ${model.cylinderType.name}"),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
if (model.deliveredQuantity != null)
|
|
|
|
|
final startEditing = widget.isUpdate && (widget.model.selectedForEditing ?? false);
|
|
|
|
|
return Form(
|
|
|
|
|
key: _formKey,
|
|
|
|
|
child: Column(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
children: [
|
|
|
|
|
Row(
|
|
|
|
|
children: [
|
|
|
|
|
const Text("Delivered Quantity: "),
|
|
|
|
|
Text(model.deliveredQuantity.toStringAsFixed(0)),
|
|
|
|
|
Expanded(child: Text(widget.model.type.name)),
|
|
|
|
|
IconButton(onPressed: widget.onPressed, color: widget.isUpdate ? AColors.cyan : AColors.red, icon: Icon(widget.isUpdate ? Icons.edit : Icons.delete))
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
if (startEditing) const SizedBox(height: 16),
|
|
|
|
|
if (startEditing) ASubTitle(subtitle.deliveredQuantity),
|
|
|
|
|
if (startEditing) const SizedBox(height: 4),
|
|
|
|
|
if (startEditing)
|
|
|
|
|
ATextFormField(
|
|
|
|
|
initialValue: model.deliveredQuantity?.toString() ?? "0",
|
|
|
|
|
textAlign: TextAlign.center,
|
|
|
|
|
// controller: deliveredQuantityController,
|
|
|
|
|
style: Theme.of(context).textTheme.subtitle1,
|
|
|
|
|
// validator: (value) => Validator.isNumeric(value) ? null : "allow numbers only",
|
|
|
|
|
textInputType: TextInputType.number,
|
|
|
|
|
// onSaved: (value) {
|
|
|
|
|
// print("value:$value");
|
|
|
|
|
// deliveredQuantity = double.tryParse(value) ?? 0;
|
|
|
|
|
// print("valueAfter:$value");
|
|
|
|
|
// // _currentDetails?.deliveredQuantity = double.tryParse(value);
|
|
|
|
|
// },
|
|
|
|
|
onChange: (value) {
|
|
|
|
|
if(value.isNotEmpty) {
|
|
|
|
|
model.deliveredQuantity = double.tryParse(value);
|
|
|
|
|
} else {
|
|
|
|
|
model.deliveredQuantity = 0;
|
|
|
|
|
}
|
|
|
|
|
print("value:$value");
|
|
|
|
|
deliveredQuantity = double.tryParse(value) ?? 0;
|
|
|
|
|
print("valueAfter:$value");
|
|
|
|
|
// _currentDetails?.deliveredQuantity = double.tryParse(value);
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
if (startEditing) const SizedBox(height: 8),
|
|
|
|
|
if (startEditing)
|
|
|
|
|
AButton(
|
|
|
|
|
text: subtitle.edit,
|
|
|
|
|
onPressed: () {
|
|
|
|
|
// print("deliveredQuantity:$deliveredQuantity");
|
|
|
|
|
// if (deliveredQuantity != null) {
|
|
|
|
|
// model.deliveredQuantity = deliveredQuantity;
|
|
|
|
|
// print("deliveredQuantity:${model.deliveredQuantity}");
|
|
|
|
|
onPressed();
|
|
|
|
|
// }
|
|
|
|
|
},
|
|
|
|
|
Wrap(
|
|
|
|
|
spacing: 10,
|
|
|
|
|
children: [
|
|
|
|
|
Text("Quantity: ${widget.model.requestedQuantity.toStringAsFixed(0)}"),
|
|
|
|
|
Text("Cylinder Size: ${widget.model.cylinderSize.name}"),
|
|
|
|
|
Text("Cylinder Type: ${widget.model.cylinderType.name}"),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
const Divider(),
|
|
|
|
|
],
|
|
|
|
|
if (widget.model.deliveredQuantity != null)
|
|
|
|
|
Row(
|
|
|
|
|
children: [
|
|
|
|
|
const Text("Delivered Quantity: "),
|
|
|
|
|
Text(widget.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: widget.model.deliveredQuantity?.toString() ?? "0",
|
|
|
|
|
textAlign: TextAlign.center,
|
|
|
|
|
style: Theme.of(context).textTheme.titleMedium,
|
|
|
|
|
// validator: (value) => Validator.isNumeric(value) ? null : "allow numbers only",
|
|
|
|
|
textInputType: TextInputType.number,
|
|
|
|
|
onSaved: (value) {
|
|
|
|
|
if (value.isNotEmpty) {
|
|
|
|
|
widget.model.deliveredQuantity = double.tryParse(value);
|
|
|
|
|
} else {
|
|
|
|
|
widget.model.deliveredQuantity = 0;
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
if (startEditing) const SizedBox(height: 8),
|
|
|
|
|
if (startEditing)
|
|
|
|
|
AButton(
|
|
|
|
|
text: subtitle.edit,
|
|
|
|
|
onPressed: () {
|
|
|
|
|
_formKey.currentState?.save();
|
|
|
|
|
widget.onPressed();
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
const Divider(),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|