@@ -398,6 +398,67 @@ void main() {
398
398
expect (find.text (errorTextField), findsNothing);
399
399
});
400
400
});
401
+
402
+ group ('errors -' , () {
403
+ testWidgets ('Should get errors when more than one fields are invalid' ,
404
+ (tester) async {
405
+ const textFieldName = 'text' ;
406
+ const checkboxName = 'checkbox' ;
407
+ const textFieldError = 'error text' ;
408
+ const checkboxError = 'error checkbox' ;
409
+ final testTextField = FormBuilderTextField (
410
+ name: textFieldName,
411
+ validator: (value) => textFieldError,
412
+ );
413
+ final testCheckbox = FormBuilderCheckbox (
414
+ title: const Text ('title' ),
415
+ name: checkboxName,
416
+ validator: (value) => checkboxError,
417
+ );
418
+ await tester.pumpWidget (buildTestableFieldWidget (
419
+ Column (children: [testTextField, testCheckbox]),
420
+ autovalidateMode: AutovalidateMode .always,
421
+ ));
422
+
423
+ expect (
424
+ formKey.currentState? .errors,
425
+ equals ({
426
+ textFieldName: textFieldError,
427
+ checkboxName: checkboxError,
428
+ }),
429
+ );
430
+ });
431
+ testWidgets ('Should get errors when one field are invalid' , (tester) async {
432
+ const textFieldName = 'text' ;
433
+ const textFieldError = 'error text' ;
434
+ final testTextField = FormBuilderTextField (
435
+ name: textFieldName,
436
+ validator: (value) => textFieldError,
437
+ );
438
+ await tester.pumpWidget (buildTestableFieldWidget (
439
+ testTextField,
440
+ autovalidateMode: AutovalidateMode .always,
441
+ ));
442
+
443
+ expect (
444
+ formKey.currentState? .errors,
445
+ equals ({textFieldName: textFieldError}),
446
+ );
447
+ });
448
+ testWidgets ('Should not get errors when all fields are valid' ,
449
+ (tester) async {
450
+ const textFieldName = 'text' ;
451
+ final testTextField = FormBuilderTextField (
452
+ name: textFieldName,
453
+ );
454
+ await tester.pumpWidget (buildTestableFieldWidget (
455
+ testTextField,
456
+ autovalidateMode: AutovalidateMode .always,
457
+ ));
458
+
459
+ expect (formKey.currentState? .errors, equals ({}));
460
+ });
461
+ });
401
462
}
402
463
403
464
// simple stateful widget that can hide and show its child with the intent of
0 commit comments