Repository: flutter
Issue: Cannot test code with dart:io File async API
Labels: a: tests,framework,has reproducible steps,P3,found in release: 2.10,found in release: 2.13,team-framework,triaged-framework

## Steps to Reproduce

I use the File API of dart:io inside a flutter widget with a periodic Timer. The code works but I'm unable to make it work on test.

**Expected results:** <!-- what did you want to see? -->

print 10 times 

**Actual results:** <!-- what did you see? -->

No print

<details>
<summary>Code sample</summary>

```dart
import 'dart:async';
import 'dart:io';

import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatefulWidget {
  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  late Timer _timer;
  var i = 0;
  @override
  void initState() {
    _timer = Timer.periodic(const Duration(seconds: 1), (timer) async {
      await File('foo.txt').writeAsString('Hi !'); // Async doesn't work
      //File('foo.txt').writeAsStringSync('Hi !'); // Sync works
      print(i++);
    });
    super.initState();
  }

  @override
  void dispose() {
    _timer.cancel();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: Center(child: Text("foo")),
      ),
    );
  }
}
```

```dart
import 'package:flutter_playground/main.dart';
import 'package:flutter_test/flutter_test.dart';

void main() {
  testWidgets('should write 10 times', (WidgetTester tester) async {
      await tester.pumpWidget(MyApp());
      await tester.pump(Duration(seconds: 10));
  });
}
```

</details>

<details>
  <summary>Logs with async IO</summary>

<!--
      Run your application with `flutter run --verbose` and attach all the
      log output below between the lines with the backticks. If there is an
      exception, please see if the error message includes enough information
      to explain how to solve the issue.
-->

```
✓ should write 10 times
Exited
```

(It works without `await` keyword)
</details>

<details>
  <summary>Logs with sync IO</summary>

```
0
1
2
3
4
5
6
7
8
9
✓ should write 10 times
Exited
```
</details>

```
flutter analyze
Analyzing flutter_playground...                                         
No issues found! (ran in 3.2s)
```

```
[✓] Flutter (Channel master, 2.13.0-0.0.pre.636, on Fedora Linux 35 (KDE Plasma) 5.16.20-200.fc35.x86_64, locale
    fr_FR.UTF-8)
    • Flutter version 2.13.0-0.0.pre.636 at /home/william/Documents/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 1d84805c75 (il y a 6 heures), 2022-04-20 02:06:44 -0400
    • Engine revision 47af169980
    • Dart version 2.18.0 (build 2.18.0-37.0.dev)
    • DevTools version 2.12.2

[!] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
    • Android SDK at /home/william/Android/Sdk
    ✗ cmdline-tools component is missing
      Run `path/to/sdkmanager --install "cmdline-tools;latest"`
      See https://developer.android.com/studio/command-line for more details.
    ✗ Android license status unknown.
      Run `flutter doctor --android-licenses` to accept the SDK licenses.
      See https://flutter.dev/docs/get-started/install/linux#android-setup for more details.

[✓] Chrome - develop for the web
    • Chrome at google-chrome

[✓] Linux toolchain - develop for Linux desktop
    • clang version 13.0.0 (Fedora 13.0.0-3.fc35)
    • cmake version 3.22.2
    • ninja version 1.10.2
    • pkg-config version 1.8.0

[✓] Android Studio (version 2021.1)
    • Android Studio at /home/william/.local/share/JetBrains/Toolbox/apps/AndroidStudio/ch-0/211.7628.21.2111.8193401
    • Flutter plugin version 66.0.1
    • Dart plugin version 211.7811
    • Java version OpenJDK Runtime Environment (build 11.0.11+0-b60-7590822)

[✓] VS Code (version 1.66.2)
    • VS Code at /usr/share/code
    • Flutter extension version 3.38.1

[✓] Connected device (2 available)
    • Linux (desktop) • linux  • linux-x64      • Fedora Linux 35 (KDE Plasma) 5.16.20-200.fc35.x86_64
    • Chrome (web)    • chrome • web-javascript • Google Chrome 100.0.4896.127

[✓] HTTP Host Availability
    • All required HTTP hosts are available

! Doctor found issues in 1 category.
```