@@ -43,6 +43,53 @@ void main() {
4343 // The field should be valid again
4444 expect (decorationFieldKey.currentState? .isValid, isTrue);
4545 });
46+
47+ testWidgets ('when set errorBuilder then show a custom widget on error' , (
48+ widgetTester,
49+ ) async {
50+ final decorationFieldKey = GlobalKey <FormBuilderFieldDecorationState >();
51+ const name = 'testField' ;
52+ const errorTextField = 'error text field' ;
53+ final errorTextKey = Key ('errorTextKey' );
54+ final widget = FormBuilderFieldDecoration <String >(
55+ key: decorationFieldKey,
56+ name: name,
57+ errorBuilder: (context, errorText) {
58+ return Text (
59+ errorText,
60+ key: errorTextKey,
61+ style: const TextStyle (color: Colors .red),
62+ );
63+ },
64+ builder: (FormFieldState <String ?> field) {
65+ return InputDecorator (
66+ decoration: (field as FormBuilderFieldDecorationState ).decoration,
67+ child: TextField (
68+ onChanged: (value) {
69+ field.didChange (value);
70+ },
71+ ),
72+ );
73+ },
74+ );
75+
76+ await widgetTester.pumpWidget (buildTestableFieldWidget (widget));
77+
78+ // Initially, the field should be valid
79+ expect (decorationFieldKey.currentState? .isValid, isTrue);
80+
81+ decorationFieldKey.currentState? .invalidate (errorTextField);
82+
83+ // The field should be invalid
84+ expect (decorationFieldKey.currentState? .isValid, isFalse);
85+
86+ await widgetTester.pumpAndSettle ();
87+
88+ // Check if the custom error widget is displayed
89+ expect (find.text (errorTextField), findsOneWidget);
90+ expect (find.byKey (errorTextKey), findsOneWidget);
91+ });
92+
4693 group ('decoration enabled -' , () {
4794 testWidgets (
4895 'when change the error text then the field should be invalid' ,
0 commit comments