From 80b2342fd47d5e3e08abf0f93d7fc7acdc322c52 Mon Sep 17 00:00:00 2001 From: Daniele Date: Mon, 9 Feb 2026 18:10:28 +0100 Subject: [PATCH 1/2] Fix for form builder: group with default datetime or TimeOfDay value and a validator as array --- lib/src/models/form_builder.dart | 4 +- test/src/models/form_builder_test.dart | 67 ++++++++++++++++++++++++++ 2 files changed, 69 insertions(+), 2 deletions(-) diff --git a/lib/src/models/form_builder.dart b/lib/src/models/form_builder.dart index 52933d8..22a4352 100644 --- a/lib/src/models/form_builder.dart +++ b/lib/src/models/form_builder.dart @@ -244,9 +244,9 @@ class FormBuilder { } else if (value is double) { return FormControl(value: value, validators: validators); } else if (value is DateTime) { - return FormControl(value: value); + return FormControl(value: value, validators: validators); } else if (value is TimeOfDay) { - return FormControl(value: value); + return FormControl(value: value, validators: validators); } return FormControl(value: value, validators: validators); diff --git a/test/src/models/form_builder_test.dart b/test/src/models/form_builder_test.dart index cc26001..34e0491 100644 --- a/test/src/models/form_builder_test.dart +++ b/test/src/models/form_builder_test.dart @@ -411,6 +411,40 @@ void main() { ); }); + + test('Build a group with default datetime value and a validator as array', () { + // Given: a form group builder creation + final requiredValidator = Validators.required; + final value = DateTime.now(); + final form = fb.group({ + 'control': [value, requiredValidator], + }); + + // Expect a form group created + expect( + form.control('control') is FormControl, + true, + reason: + '${form.control('control').runtimeType} is not instance of FormControl', + ); + expect( + form.control('control').value, + value, + reason: 'control default value not set', + ); + expect( + form.control('control').validators.length, + 1, + reason: 'incorrect validators length' + ); + expect( + form.control('control').validators[0], + requiredValidator, + reason: 'not set required validator' + ); + }); + + test('Build a group with default TimeOfDay value as array', () { // Given: a form group builder creation final value = TimeOfDay.now(); @@ -432,6 +466,39 @@ void main() { ); }); + + test('Build a group with default TimeOfDay value and a validator as array', () { + // Given: a form group builder creation + final requiredValidator = Validators.required; + final value = TimeOfDay.now(); + final form = fb.group({ + 'control': [value, requiredValidator], + }); + + // Expect a form group created + expect( + form.control('control') is FormControl, + true, + reason: + '${form.control('control').runtimeType} is not instance of FormControl', + ); + expect( + form.control('control').value, + value, + reason: 'control default value not set', + ); + expect( + form.control('control').validators.length, + 1, + reason: 'incorrect validators length' + ); + expect( + form.control('control').validators[0], + requiredValidator, + reason: 'not set required validator' + ); + }); + test('Build a state with ', () { // Given: a state creation final state = fb.state(value: 'name', disabled: true); From b708239b31bb0e6cc3b6e387f192faa5c8cc7ee3 Mon Sep 17 00:00:00 2001 From: Daniele Date: Mon, 9 Feb 2026 18:36:18 +0100 Subject: [PATCH 2/2] Fixes after Gemini Code Review --- test/src/models/form_builder_test.dart | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/test/src/models/form_builder_test.dart b/test/src/models/form_builder_test.dart index 34e0491..de9156a 100644 --- a/test/src/models/form_builder_test.dart +++ b/test/src/models/form_builder_test.dart @@ -422,8 +422,8 @@ void main() { // Expect a form group created expect( - form.control('control') is FormControl, - true, + form.control('control'), + isA>(), reason: '${form.control('control').runtimeType} is not instance of FormControl', ); @@ -433,13 +433,8 @@ void main() { reason: 'control default value not set', ); expect( - form.control('control').validators.length, - 1, - reason: 'incorrect validators length' - ); - expect( - form.control('control').validators[0], - requiredValidator, + form.control('control').validators, + [requiredValidator], reason: 'not set required validator' ); }); @@ -477,8 +472,8 @@ void main() { // Expect a form group created expect( - form.control('control') is FormControl, - true, + form.control('control'), + isA>(), reason: '${form.control('control').runtimeType} is not instance of FormControl', ); @@ -488,13 +483,8 @@ void main() { reason: 'control default value not set', ); expect( - form.control('control').validators.length, - 1, - reason: 'incorrect validators length' - ); - expect( - form.control('control').validators[0], - requiredValidator, + form.control('control').validators, + [requiredValidator], reason: 'not set required validator' ); });