Browse Source

validate supply form when editting

smf
daivp 4 years ago
parent
commit
428daf6233
2 changed files with 56 additions and 2 deletions
  1. +18
    -0
      lib/presentation/screens/actions/nursery/widget_worker.dart
  2. +38
    -2
      lib/presentation/screens/actions/sc_action.dart

+ 18
- 0
lib/presentation/screens/actions/nursery/widget_worker.dart View File

@@ -1,5 +1,6 @@
import 'package:farm_tpf/custom_model/action_form/RequestActivity.dart';
import 'package:farm_tpf/presentation/custom_widgets/widget_utils.dart';
import 'package:farm_tpf/presentation/screens/actions/controller/ChangeFieldInForm.dart';
import 'package:farm_tpf/presentation/screens/actions/controller/ChangeWorker.dart';
import 'package:farm_tpf/utils/const_string.dart';
import 'package:farm_tpf/utils/validators.dart';
@@ -20,11 +21,13 @@ class _WidgetWorkerState extends State<WidgetWorker> {
TextEditingController _workerNameController = TextEditingController();
TextEditingController _trayNumberController = TextEditingController();
ChangeWorker controller;
final changeFormField = Get.put(ChangeFieldFormSupply());
@override
void initState() {
super.initState();
controller = Get.put(ChangeWorker());
controller.init([]);
changeFormField.init();
}

Widget _buildListWorker() {
@@ -146,12 +149,26 @@ class _WidgetWorkerState extends State<WidgetWorker> {
value, label_validate_input_empty);
},
onSaved: (newValue) {},
onChanged: (value) {
if (!Validators.stringNotNullOrEmpty(value)) {
changeFormField.change(false);
} else {
changeFormField.change(true);
}
},
),
TextFormField(
keyboardType: TextInputType.text,
controller: _trayNumberController,
decoration: InputDecoration(labelText: "Ươm khây số"),
onSaved: (newValue) {},
onChanged: (value) {
if (!Validators.stringNotNullOrEmpty(value)) {
changeFormField.change(false);
} else {
changeFormField.change(true);
}
},
),
],
),
@@ -171,6 +188,7 @@ class _WidgetWorkerState extends State<WidgetWorker> {
controller.addNurseryDetail(_nurseryDetail);
_workerNameController.clear();
_trayNumberController.clear();
changeFormField.change(false);
} else {
Utils.showSnackBarWarning(
message: "Vui lòng nhập tên công nhân");

+ 38
- 2
lib/presentation/screens/actions/sc_action.dart View File

@@ -29,6 +29,7 @@ import 'package:get/get.dart';
import 'package:keyboard_dismisser/keyboard_dismisser.dart';
import 'package:farm_tpf/utils/formatter.dart';

import 'controller/ChangeFieldInForm.dart';
import 'controller/ChangeSupplyUsing.dart';
import 'controller/ChangeWorker.dart';
import 'dung/widget_dung_supply.dart';
@@ -86,6 +87,41 @@ class _ActionScreenState extends State<ActionScreen> {
changeFileController.initValue();
}

_submitForm() async {
switch (widget.activityType) {
case 'ACTIVE_TYPE_NURSERY':
if (Get.find<ChangeFieldFormSupply>().isChanged) {
Utils.showDialog(
title: 'Thông tin người thực hiện chưa cập nhật',
message: 'Bạn có muốn cập nhật',
textConfirm: 'Tiếp tục',
textCancel: 'Xem lại',
onConfirm: () {
Get.back();
_validateInputs();
});
} else {
_validateInputs();
}
break;
case 'ACTIVE_TYPE_PLANTING':
case 'ACTIVE_TYPE_FERTILIZE':
case 'ACTIVE_TYPE_SPRAYING_PESTICIDES':
if (Get.find<ChangeFieldFormSupply>().isChanged) {
Utils.showDialogConfirmSupply(onConfirm: () {
Get.back();
_validateInputs();
});
} else {
_validateInputs();
}
break;
default:
_validateInputs();
break;
}
}

_validateInputs() async {
if (_formKey.currentState.validate()) {
_formKey.currentState.save();
@@ -434,7 +470,7 @@ class _ActionScreenState extends State<ActionScreen> {
if (!currentFocus.hasPrimaryFocus) {
currentFocus.unfocus();
}
_validateInputs();
_submitForm();
},
),
),
@@ -549,7 +585,7 @@ class _ActionScreenState extends State<ActionScreen> {
if (!currentFocus.hasPrimaryFocus) {
currentFocus.unfocus();
}
_validateInputs();
_submitForm();
}),
),
],

Loading…
Cancel
Save