Repository: flutter
Issue: Missing SemanticsNode of TextFormField's validator text when using `tester.pump`
Labels: a: tests,a: text input,framework,a: accessibility,has reproducible steps,P2,found in release: 3.19,team-text-input,triaged-text-input,found in release: 3.22

### Steps to reproduce

I found this odd behaviour in testing `TextFormField` validation. 

I created a small app with one `TextFormField` and one submit `ElevatedButton`. When you submit with empty `TextFormField`, you'll get an `errorText` (of `InputDecoration` of `TextFormField`) saying "validation error".

I wrote a test for that by pumping the app widget, then tapping submit and doing either `pump` or `pumpAndSettle` then checking if "validation error" exists both on screen and in semantics.

The test passes for finding "validation error" on screen but the issue is finding semantics does not pass when using `pump` and it does not show in semantics tree. Although it passes using `pumpAndSettle` but documentation discourages from using `pumpAndSettle` in general.

Is it a bug? Is `pump` suppose to show `errorText` on screen but not on semantics tree?

### Expected results

When I use `tap` then `pump`, test `find.bySemanticsLabel` should pass for the `errorText` cases and `label: "validation error"` should be displayed in the semantics tree

### Actual results

I get this error:
```
Expected: exactly one matching candidate
  Actual: _ElementPredicateWidgetFinder:<Found 0 widgets with element matching predicate: []>
   Which: means none were found but one was expected
```

Also `SemanticsNode#6` in the logs below does not show `label: "validation error"`

### Code sample

<details open><summary>lib/main.dart</summary>

```dart
import 'package:flutter/material.dart';

void main() {
  runApp(const MainApp());
}

class MainApp extends StatefulWidget {
  const MainApp({super.key});

  @override
  State<MainApp> createState() => _MainAppState();
}

class _MainAppState extends State<MainApp> {
  final _formKey = GlobalKey<FormState>();

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: SafeArea(
        child: Scaffold(
          body: Form(
            key: _formKey,
            child: Column(
              children: [
                TextFormField(
                  decoration: const InputDecoration(
                    labelText: 'Name',
                  ),
                  validator: (value) {
                    if (value == null || value.trim().isEmpty) {
                      return 'validation error';
                    }
                    return null;
                  },
                ),
                ElevatedButton(
                    onPressed: () {
                      if (_formKey.currentState!.validate()) {
                        // Process data...
                      }
                    },
                    child: const Text('Submit')),
              ],
            ),
          ),
        ),
      ),
    );
  }
}
```

</details>

<details open><summary>test/widget_test.dart</summary>

```dart
import 'package:flutter/rendering.dart';
import 'package:flutter_test/flutter_test.dart';

// Change package name accordingly
import 'package:flutter_textfield_a11y/main.dart';

void main() {
  testWidgets('Test TextField Semantics', (tester) async {
    await tester.pumpWidget(const MainApp());

    // Tap submit Button
    await tester.tap(find.text('Submit'));

    // pump vs pumpAndSettle
    // Try running the test with each line to see the difference
    await tester.pump();
    // await tester.pumpAndSettle();

    // SemanticsTree After
    debugDumpSemanticsTree();

    // This line passes for both pump and pumpAndSettle
    expect(find.text('validation error'), findsOneWidget);

    // The issue is in this line. It does not pass using pump but passes using pumpAndSettle
    expect(find.bySemanticsLabel(RegExp('validation error')), findsOneWidget);
  });
}

```

</details>


### Screenshots or Video

<details open>
<summary>Screenshots / Video demonstration</summary>

[Upload media here]

</details>


### Logs

<details open><summary>pump</summary>

```console
SemanticsNode#0
 │ Rect.fromLTRB(0.0, 0.0, 2400.0, 1800.0)
 │
 └─SemanticsNode#1
   │ Rect.fromLTRB(0.0, 0.0, 800.0, 600.0) scaled by 3.0x
   │ textDirection: ltr
   │
   └─SemanticsNode#2
     │ Rect.fromLTRB(0.0, 0.0, 800.0, 600.0)
     │ sortKey: OrdinalSortKey#c8661(order: 0.0)
     │
     └─SemanticsNode#3
       │ Rect.fromLTRB(0.0, 0.0, 800.0, 600.0)
       │ flags: scopesRoute
       │
       ├─SemanticsNode#4
       │ │ Rect.fromLTRB(0.0, 0.0, 800.0, 88.0)
       │ │ actions: tap
       │ │ flags: isTextField
       │ │ label: "Name"
       │ │ textDirection: ltr
       │ │ currentValueLength: 0
       │ │
       │ └─SemanticsNode#6
       │     Rect.fromLTRB(0.0, 72.0, 198.4, 88.0)
       │
       └─SemanticsNode#5
           Rect.fromLTRB(333.7, 88.0, 466.3, 136.0)
           actions: tap
           flags: isButton, hasEnabledState, isEnabled, isFocusable
           label: "Submit"
           textDirection: ltr
           thickness: 1.0

══╡ EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK ╞════════════════════════════════════════════════════
The following TestFailure was thrown running a test:
Expected: exactly one matching candidate
  Actual: _ElementPredicateWidgetFinder:<Found 0 widgets with element matching predicate: []>
   Which: means none were found but one was expected

When the exception was thrown, this was the stack:
#4      main.<anonymous closure> (file:///Users/anasqaderi/Coding/play/flutter_textfield_a11y/test/widget_test.dart:26:5)
<asynchronous suspension>
#5      testWidgets.<anonymous closure>.<anonymous closure> (package:flutter_test/src/widget_tester.dart:183:15)
<asynchronous suspension>
#6      TestWidgetsFlutterBinding._runTestBody (package:flutter_test/src/binding.dart:1017:5)
<asynchronous suspension>
<asynchronous suspension>
(elided one frame from package:stack_trace)

This was caught by the test expectation on the following line:
  file:///Users/anasqaderi/Coding/play/flutter_textfield_a11y/test/widget_test.dart line 26
The test description was:
  Test TextField Semantics
════════════════════════════════════════════════════════════════════════════════════════════════════
```

</details>

<details open><summary>pumpAndSettle</summary>

```console
SemanticsNode#0
 │ Rect.fromLTRB(0.0, 0.0, 2400.0, 1800.0)
 │
 └─SemanticsNode#1
   │ Rect.fromLTRB(0.0, 0.0, 800.0, 600.0) scaled by 3.0x
   │ textDirection: ltr
   │
   └─SemanticsNode#2
     │ Rect.fromLTRB(0.0, 0.0, 800.0, 600.0)
     │ sortKey: OrdinalSortKey#99899(order: 0.0)
     │
     └─SemanticsNode#3
       │ Rect.fromLTRB(0.0, 0.0, 800.0, 600.0)
       │ flags: scopesRoute
       │
       ├─SemanticsNode#4
       │ │ Rect.fromLTRB(0.0, 0.0, 800.0, 88.0)
       │ │ actions: tap
       │ │ flags: isTextField
       │ │ label: "Name"
       │ │ textDirection: ltr
       │ │ currentValueLength: 0
       │ │
       │ └─SemanticsNode#6
       │     Rect.fromLTRB(0.0, 72.0, 198.4, 88.0)
       │     label: "validation error"
       │     textDirection: ltr
       │
       └─SemanticsNode#5
           Rect.fromLTRB(333.7, 88.0, 466.3, 136.0)
           actions: tap
           flags: isButton, hasEnabledState, isEnabled, isFocusable
           label: "Submit"
           textDirection: ltr
           thickness: 1.0
```

</details>


### Flutter Doctor output

<details open><summary>Doctor output</summary>

```console
[✓] Flutter (Channel stable, 3.19.6, on macOS 14.4.1 23E224 darwin-arm64, locale en-AU)
    • Flutter version 3.19.6 on channel stable at /Users/anasqaderi/Coding/exe/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 54e66469a9 (7 hours ago), 2024-04-17 13:08:03 -0700
    • Engine revision c4cd48e186
    • Dart version 3.3.4
    • DevTools version 2.31.1

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at /Users/anasqaderi/Library/Android/sdk
    • Platform android-34, build-tools 34.0.0
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b829.9-10027231)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 15.3)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 15E204a
    • CocoaPods version 1.14.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2022.3)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b829.9-10027231)

[✓] VS Code (version 1.88.0)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.86.0

[✓] Connected device (4 available)            
    • Anas iPhone 15 Pro Max (mobile) • 00008130-001079A10A98001C • ios            • iOS 17.4.1 21E236
    • Anas iPhone XS Max (mobile)     • 00008020-000E6CCA1104002E • ios            • iOS 17.4.1 21E236
    • macOS (desktop)                 • macos                     • darwin-arm64   • macOS 14.4.1 23E224 darwin-arm64
    • Chrome (web)                    • chrome                    • web-javascript • Google Chrome 124.0.6367.61

[✓] Network resources
    • All expected network resources are available.

• No issues found!
```

</details>