@@ -164,7 +164,6 @@ void main() {
164
164
expect (textFieldKey.currentState? .valueHasError, isTrue);
165
165
});
166
166
});
167
-
168
167
group ('autovalidateMode -' , () {
169
168
testWidgets (
170
169
'Should show error when init form and AutovalidateMode is always' ,
@@ -201,7 +200,6 @@ void main() {
201
200
expect (find.text (errorTextField), findsOneWidget);
202
201
});
203
202
});
204
-
205
203
group ('isDirty - ' , () {
206
204
testWidgets ('Should not dirty by default' , (tester) async {
207
205
const textFieldName = 'text' ;
@@ -301,7 +299,6 @@ void main() {
301
299
expect (textFieldKey.currentState? .isDirty, false );
302
300
});
303
301
});
304
-
305
302
group ('isTouched - ' , () {
306
303
testWidgets ('Should not touched by default' , (tester) async {
307
304
const textFieldName = 'text' ;
@@ -325,7 +322,6 @@ void main() {
325
322
expect (textFieldKey.currentState? .isTouched, true );
326
323
});
327
324
});
328
-
329
325
group ('reset -' , () {
330
326
testWidgets ('Should reset to null when call reset' , (tester) async {
331
327
const textFieldName = 'text' ;
@@ -378,5 +374,56 @@ void main() {
378
374
expect (find.text (errorTextField), findsNothing);
379
375
});
380
376
});
377
+ group ('focus -' , () {
378
+ testWidgets ('Should focus on field when invalidate it' , (tester) async {
379
+ final textFieldKey = GlobalKey <FormBuilderFieldState >();
380
+ const widgetName = 'text' ;
381
+ const errorTextField = 'error text field' ;
382
+ final testWidget = FormBuilderTextField (
383
+ name: widgetName,
384
+ key: textFieldKey,
385
+ );
386
+ final widgetFinder = find.byWidget (testWidget);
387
+
388
+ await tester.pumpWidget (buildTestableFieldWidget (testWidget));
389
+ final focusNode =
390
+ formKey.currentState? .fields[widgetName]? .effectiveFocusNode;
391
+
392
+ expect (Focus .of (tester.element (widgetFinder)).hasFocus, false );
393
+ expect (focusNode? .hasFocus, false );
394
+
395
+ textFieldKey.currentState? .invalidate (errorTextField);
396
+ await tester.pumpAndSettle ();
397
+
398
+ expect (Focus .of (tester.element (widgetFinder)).hasFocus, true );
399
+ expect (focusNode? .hasFocus, true );
400
+ });
401
+ testWidgets (
402
+ 'Should not focus on field when invalidate field and is disabled' ,
403
+ (tester) async {
404
+ final textFieldKey = GlobalKey <FormBuilderFieldState >();
405
+ const widgetName = 'text' ;
406
+ const errorTextField = 'error text field' ;
407
+ final testWidget = FormBuilderTextField (
408
+ name: widgetName,
409
+ key: textFieldKey,
410
+ enabled: false ,
411
+ );
412
+ final widgetFinder = find.byWidget (testWidget);
413
+
414
+ await tester.pumpWidget (buildTestableFieldWidget (testWidget));
415
+ final focusNode =
416
+ formKey.currentState? .fields[widgetName]? .effectiveFocusNode;
417
+
418
+ expect (Focus .of (tester.element (widgetFinder)).hasFocus, false );
419
+ expect (focusNode? .hasFocus, false );
420
+
421
+ textFieldKey.currentState? .invalidate (errorTextField);
422
+ await tester.pumpAndSettle ();
423
+
424
+ expect (Focus .of (tester.element (widgetFinder)).hasFocus, false );
425
+ expect (focusNode? .hasFocus, false );
426
+ });
427
+ });
381
428
});
382
429
}
0 commit comments