Repository: flutter/flutter
File: packages/flutter/test/widgets/overlay_portal_test.dart (Dart)

Code before:

    controller.show();
    await tester.pump();

    expect(overlayChildData?.padding, expectedPadding);
    expect(overlayChildData?.viewInsets, expectedViewInsets);
    expect(overlayChildData?.viewPadding, expectedViewPadding);
    expect(overlayChildData?.size, expectedSize);
  });

  testWidgets('The overlay portal update semantics does not dirty overlay', (
    WidgetTester tester,
  ) async {
    late StateSetter setState;
    late final OverlayEntry overlayEntry;
    final overlayKey = UniqueKey();
    var msg = 'msg';
    addTearDown(
      () => overlayEntry
        ..remove()
        ..dispose(),
    );

    await tester.pumpWidget(
      Directionality(
        textDirection: TextDirection.ltr,
        child: Semantics(
          container: true,
          child: Overlay(
            key: overlayKey,
            initialEntries: <OverlayEntry>[
              overlayEntry = OverlayEntry(
                builder: (BuildContext context) {
                  return Semantics(
                    container: true,
                    explicitChildNodes: true,
                    child: StatefulBuilder(
                      builder: (BuildContext context, StateSetter setter) {
                        setState = setter;
                        return OverlayPortal(
                          controller: controller1,
                          overlayChildBuilder: (BuildContext context) {
                            return Semantics(
                              label: msg,
                              child: const SizedBox(width: 100, height: 100),
                            );
                          },
                          child: const Text('overlay child'),
                        );
                      },
                    ),

Review comment (suggestion):
```suggestion
    MediaQueryData? overlayChildData;
    late final OverlayEntry entry;
    addTearDown(() {
       entry.remove();
       entry.dispose();
    });
```

Code after:
                    );
                  },
                ),
              ],
            ),
          ),
        ),
      );

      controller.show();
      await tester.pump();

      expect(overlayChildData?.padding, rootPadding);
    },
  );

  testWidgets('OverlayPortal overlayChild receives MediaQuery properties from Overlay context', (
    WidgetTester tester,
  ) async {
    final controller = OverlayPortalController();
    const expectedPadding = EdgeInsets.all(10);
    const expectedViewInsets = EdgeInsets.only(bottom: 300);
    const expectedViewPadding = EdgeInsets.only(top: 50, bottom: 20);
    const expectedSize = Size(800, 600);

    MediaQueryData? overlayChildData;
    OverlayEntry? entry;
    addTearDown(() {
      entry?.remove();
      entry?.dispose();
    });

    await tester.pumpWidget(
      MediaQuery(
        data: const MediaQueryData(
          padding: expectedPadding,
          viewInsets: expectedViewInsets,
          viewPadding: expectedViewPadding,
          size: expectedSize,
        ),
        child: Directionality(
          textDirection: TextDirection.ltr,
          child: Overlay(
            initialEntries: <OverlayEntry>[
              entry = OverlayEntry(
                builder: (BuildContext context) {
                  return MediaQuery(
                    data: MediaQuery.of(context).copyWith(
                      padding: EdgeInsets.zero,
                      viewInsets: EdgeInsets.zero,
                      viewPadding: EdgeInsets.zero,