simplified code across the app and consolidated duplicated helpers
This commit is contained in:
@@ -30,6 +30,12 @@ class _AbsenceReportViewState extends State<AbsenceReportView> {
|
||||
final TextEditingController _lastName = TextEditingController();
|
||||
final TextEditingController _phone = TextEditingController();
|
||||
final TextEditingController _note = TextEditingController();
|
||||
late final List<TextEditingController> _textControllers = [
|
||||
_firstName,
|
||||
_lastName,
|
||||
_phone,
|
||||
_note,
|
||||
];
|
||||
final AsyncActionController _submitController = AsyncActionController();
|
||||
|
||||
late Future<void> _init;
|
||||
@@ -46,7 +52,7 @@ class _AbsenceReportViewState extends State<AbsenceReportView> {
|
||||
final today = DateUtils.dateOnly(DateTime.now());
|
||||
_absentFrom = today;
|
||||
_absentUntil = today;
|
||||
for (final c in [_firstName, _lastName, _phone, _note]) {
|
||||
for (final c in _textControllers) {
|
||||
c.addListener(_onFieldChanged);
|
||||
}
|
||||
_init = _load();
|
||||
@@ -54,7 +60,7 @@ class _AbsenceReportViewState extends State<AbsenceReportView> {
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
for (final c in [_firstName, _lastName, _phone, _note]) {
|
||||
for (final c in _textControllers) {
|
||||
c.dispose();
|
||||
}
|
||||
_submitController.dispose();
|
||||
@@ -290,13 +296,11 @@ class _AbsenceReportViewState extends State<AbsenceReportView> {
|
||||
String? _requiredError(TextEditingController controller) =>
|
||||
_submitted && controller.text.trim().isEmpty ? _required : null;
|
||||
|
||||
InputDecoration _decoration(String label, {String? error, String? hint}) =>
|
||||
InputDecoration(
|
||||
border: const OutlineInputBorder(),
|
||||
labelText: label,
|
||||
hintText: hint,
|
||||
errorText: error,
|
||||
);
|
||||
InputDecoration _decoration(String label, {String? error}) => InputDecoration(
|
||||
border: const OutlineInputBorder(),
|
||||
labelText: label,
|
||||
errorText: error,
|
||||
);
|
||||
}
|
||||
|
||||
/// Terminal success screen shown in place of the form after a report was
|
||||
|
||||
Reference in New Issue
Block a user