|
|
|
|
@ -16,9 +16,10 @@ class PartNoButton extends StatefulWidget {
|
|
|
|
|
final List<SparePart> spareParts;
|
|
|
|
|
final List<SparePartsWorkOrders> initialList;
|
|
|
|
|
final TextEditingController controller;
|
|
|
|
|
final bool disablePartEdit;
|
|
|
|
|
final Function(List<SparePartsWorkOrders> sparePart) onChange;
|
|
|
|
|
|
|
|
|
|
const PartNoButton({@required this.spareParts, @required this.controller, this.initialList, this.onChange, Key key}) : super(key: key);
|
|
|
|
|
const PartNoButton({@required this.spareParts, @required this.controller, this.initialList, this.onChange, this.disablePartEdit = false, Key key}) : super(key: key);
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
State<PartNoButton> createState() => _PartNoButtonState();
|
|
|
|
|
@ -93,17 +94,19 @@ class _PartNoButtonState extends State<PartNoButton> {
|
|
|
|
|
label: context.translation.add,
|
|
|
|
|
maxWidth: true,
|
|
|
|
|
textColor: Colors.white,
|
|
|
|
|
buttonColor: AppColor.neutral50,
|
|
|
|
|
onPressed: () {
|
|
|
|
|
if (current != null && _formKey.currentState.validate()) {
|
|
|
|
|
_formKey.currentState.save();
|
|
|
|
|
list.add(current);
|
|
|
|
|
if (widget.onChange != null) widget.onChange(list);
|
|
|
|
|
current = SparePartsWorkOrders();
|
|
|
|
|
widget.controller.text = "";
|
|
|
|
|
setState(() {});
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
buttonColor: widget.disablePartEdit ? AppColor.neutral20 : AppColor.neutral50,
|
|
|
|
|
onPressed: widget.disablePartEdit
|
|
|
|
|
? null
|
|
|
|
|
: () {
|
|
|
|
|
if (current != null && _formKey.currentState.validate()) {
|
|
|
|
|
_formKey.currentState.save();
|
|
|
|
|
list.add(current);
|
|
|
|
|
if (widget.onChange != null) widget.onChange(list);
|
|
|
|
|
current = SparePartsWorkOrders();
|
|
|
|
|
widget.controller.text = "";
|
|
|
|
|
setState(() {});
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
16.height,
|
|
|
|
|
const Divider().defaultStyle(context),
|
|
|
|
|
@ -114,17 +117,70 @@ class _PartNoButtonState extends State<PartNoButton> {
|
|
|
|
|
itemCount: list.length,
|
|
|
|
|
padding: EdgeInsets.only(bottom: 16.toScreenHeight),
|
|
|
|
|
physics: const NeverScrollableScrollPhysics(),
|
|
|
|
|
itemBuilder: (context, index) => Row(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
itemBuilder: (context, index) => Column(
|
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
|
children: [
|
|
|
|
|
"${list[index].sparePart.partNo} / ${list[index].sparePart.partName}".bodyText(context).expanded,
|
|
|
|
|
list[index].qty.toString().bodyText(context),
|
|
|
|
|
32.width,
|
|
|
|
|
"trash".toSvgAsset().onPress(() {
|
|
|
|
|
list.remove(list[index]);
|
|
|
|
|
if (widget.onChange != null) widget.onChange(list);
|
|
|
|
|
setState(() {});
|
|
|
|
|
}),
|
|
|
|
|
Row(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
children: [
|
|
|
|
|
"${list[index].sparePart.partNo} / ${list[index].sparePart.partName}".bodyText(context).expanded,
|
|
|
|
|
list[index].qty.toString().bodyText(context),
|
|
|
|
|
32.width,
|
|
|
|
|
"trash".toSvgAsset(color: widget.disablePartEdit ? Colors.grey : null).onPress(widget.disablePartEdit
|
|
|
|
|
? null
|
|
|
|
|
: () {
|
|
|
|
|
list.remove(list[index]);
|
|
|
|
|
if (widget.onChange != null) widget.onChange(list);
|
|
|
|
|
setState(() {});
|
|
|
|
|
}),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
if (widget.disablePartEdit)
|
|
|
|
|
Row(
|
|
|
|
|
children: [
|
|
|
|
|
AppTextFormField(
|
|
|
|
|
controller: TextEditingController(),
|
|
|
|
|
labelText: "Installed Qty",
|
|
|
|
|
textInputType: TextInputType.number,
|
|
|
|
|
backgroundColor: context.isDark ? AppColor.neutral20 : AppColor.neutral30,
|
|
|
|
|
enable: true,
|
|
|
|
|
initialValue: list[index].installQty?.toInt()?.toString() ?? "",
|
|
|
|
|
validator: (value) => value == null || value.isEmpty
|
|
|
|
|
? context.translation.requiredField
|
|
|
|
|
: Validator.isNumeric(value)
|
|
|
|
|
? null
|
|
|
|
|
: context.translation.onlyNumbers,
|
|
|
|
|
onChange: (text) {
|
|
|
|
|
list[index].installQty = num.tryParse(text ?? "");
|
|
|
|
|
if (widget.onChange != null) widget.onChange(list);
|
|
|
|
|
},
|
|
|
|
|
onSaved: (text) {
|
|
|
|
|
list[index].installQty = num.tryParse(text ?? "");
|
|
|
|
|
},
|
|
|
|
|
).expanded,
|
|
|
|
|
8.width,
|
|
|
|
|
AppTextFormField(
|
|
|
|
|
controller: TextEditingController(),
|
|
|
|
|
labelText: "Returned Qty",
|
|
|
|
|
textInputType: TextInputType.number,
|
|
|
|
|
backgroundColor: context.isDark ? AppColor.neutral20 : AppColor.neutral30,
|
|
|
|
|
enable: true,
|
|
|
|
|
initialValue: list[index].returnQty?.toInt()?.toString() ?? "",
|
|
|
|
|
validator: (value) => value == null || value.isEmpty
|
|
|
|
|
? context.translation.requiredField
|
|
|
|
|
: Validator.isNumeric(value)
|
|
|
|
|
? null
|
|
|
|
|
: context.translation.onlyNumbers,
|
|
|
|
|
onChange: (text) {
|
|
|
|
|
list[index].returnQty = num.tryParse(text ?? "");
|
|
|
|
|
if (widget.onChange != null) widget.onChange(list);
|
|
|
|
|
},
|
|
|
|
|
onSaved: (text) {
|
|
|
|
|
list[index].returnQty = num.tryParse(text ?? "");
|
|
|
|
|
},
|
|
|
|
|
).expanded,
|
|
|
|
|
],
|
|
|
|
|
).paddingOnly(top: 4, bottom: 4),
|
|
|
|
|
],
|
|
|
|
|
).paddingOnly(top: 4, bottom: 4),
|
|
|
|
|
separatorBuilder: (context, index) => 8.height,
|
|
|
|
|
|