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

import 'package:farm_tpf/custom_model/action_form/RequestActivity.dart'; 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/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/presentation/screens/actions/controller/ChangeWorker.dart';
import 'package:farm_tpf/utils/const_string.dart'; import 'package:farm_tpf/utils/const_string.dart';
import 'package:farm_tpf/utils/validators.dart'; import 'package:farm_tpf/utils/validators.dart';
TextEditingController _workerNameController = TextEditingController(); TextEditingController _workerNameController = TextEditingController();
TextEditingController _trayNumberController = TextEditingController(); TextEditingController _trayNumberController = TextEditingController();
ChangeWorker controller; ChangeWorker controller;
final changeFormField = Get.put(ChangeFieldFormSupply());
@override @override
void initState() { void initState() {
super.initState(); super.initState();
controller = Get.put(ChangeWorker()); controller = Get.put(ChangeWorker());
controller.init([]); controller.init([]);
changeFormField.init();
} }


Widget _buildListWorker() { Widget _buildListWorker() {
value, label_validate_input_empty); value, label_validate_input_empty);
}, },
onSaved: (newValue) {}, onSaved: (newValue) {},
onChanged: (value) {
if (!Validators.stringNotNullOrEmpty(value)) {
changeFormField.change(false);
} else {
changeFormField.change(true);
}
},
), ),
TextFormField( TextFormField(
keyboardType: TextInputType.text, keyboardType: TextInputType.text,
controller: _trayNumberController, controller: _trayNumberController,
decoration: InputDecoration(labelText: "Ươm khây số"), decoration: InputDecoration(labelText: "Ươm khây số"),
onSaved: (newValue) {}, onSaved: (newValue) {},
onChanged: (value) {
if (!Validators.stringNotNullOrEmpty(value)) {
changeFormField.change(false);
} else {
changeFormField.change(true);
}
},
), ),
], ],
), ),
controller.addNurseryDetail(_nurseryDetail); controller.addNurseryDetail(_nurseryDetail);
_workerNameController.clear(); _workerNameController.clear();
_trayNumberController.clear(); _trayNumberController.clear();
changeFormField.change(false);
} else { } else {
Utils.showSnackBarWarning( Utils.showSnackBarWarning(
message: "Vui lòng nhập tên công nhân"); message: "Vui lòng nhập tên công nhân");

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

import 'package:keyboard_dismisser/keyboard_dismisser.dart'; import 'package:keyboard_dismisser/keyboard_dismisser.dart';
import 'package:farm_tpf/utils/formatter.dart'; import 'package:farm_tpf/utils/formatter.dart';


import 'controller/ChangeFieldInForm.dart';
import 'controller/ChangeSupplyUsing.dart'; import 'controller/ChangeSupplyUsing.dart';
import 'controller/ChangeWorker.dart'; import 'controller/ChangeWorker.dart';
import 'dung/widget_dung_supply.dart'; import 'dung/widget_dung_supply.dart';
changeFileController.initValue(); 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 { _validateInputs() async {
if (_formKey.currentState.validate()) { if (_formKey.currentState.validate()) {
_formKey.currentState.save(); _formKey.currentState.save();
if (!currentFocus.hasPrimaryFocus) { if (!currentFocus.hasPrimaryFocus) {
currentFocus.unfocus(); currentFocus.unfocus();
} }
_validateInputs();
_submitForm();
}, },
), ),
), ),
if (!currentFocus.hasPrimaryFocus) { if (!currentFocus.hasPrimaryFocus) {
currentFocus.unfocus(); currentFocus.unfocus();
} }
_validateInputs();
_submitForm();
}), }),
), ),
], ],

Loading…
Cancel
Save