Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Propagates Overlay's MediaQueryData to OverlayPortal child#181579

Merged
auto-submit[bot] merged 9 commits intoflutter:masterfrom
patrickBillingsley:fix/overlay-portal-constraints
Feb 4, 2026
Merged

Propagates Overlay's MediaQueryData to OverlayPortal child#181579
auto-submit[bot] merged 9 commits intoflutter:masterfrom
patrickBillingsley:fix/overlay-portal-constraints

Conversation

@patrickBillingsley
Copy link
Contributor

@patrickBillingsley patrickBillingsley commented Jan 28, 2026

Widgets like Scaffold strip MediaQueryData causing widgets rendered in the Overlay to be obscured, e.g., by the software keyboard.

Related Issue - 142921
Related Issue - 157664

This does not directly fix these two issues but appears to be an underlying issue with both which merited this being a separate PR. I have a separate fix for the MenuAnchor that I will supply in a follow up PR.

Pre-launch Checklist

Widgets like Scaffold strip MediaQueryData causing widgets rendered in the Overlay
to be obscured, e.g., by the software keyboard.
@github-actions github-actions bot added the framework flutter/packages/flutter repository. See also f: labels. label Jan 28, 2026
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request correctly propagates MediaQueryData from the Overlay to the OverlayPortal's child to address issues with stripped media query data. The implementation logic is sound. I've suggested an improvement to the test to make it more robust and better reflect the real-world scenario it's testing, ensuring that other MediaQueryData properties are preserved as intended.

Comment on lines +157 to +207
testWidgets('OverlayPortal overlayChild receives MediaQuery properties from Overlay context', (WidgetTester tester) async {
final OverlayPortalController controller = OverlayPortalController();
final EdgeInsets expectedPadding = EdgeInsets.all(10);
final EdgeInsets expectedViewInsets = EdgeInsets.only(bottom: 300);
final EdgeInsets expectedViewPadding = EdgeInsets.only(top: 50, bottom: 20);

MediaQueryData? overlayChildData;

await tester.pumpWidget(
MediaQuery(
data: MediaQueryData(
padding: expectedPadding,
viewInsets: expectedViewInsets,
viewPadding: expectedViewPadding,
),
child: Directionality(
textDirection: TextDirection.ltr,
child: Overlay(
initialEntries: [
OverlayEntry(
builder: (context) {
return MediaQuery(
data: MediaQueryData(
padding: EdgeInsets.zero,
viewInsets: EdgeInsets.zero,
viewPadding: EdgeInsets.zero,
),
child: OverlayPortal(
controller: controller,
overlayChildBuilder: (context) {
overlayChildData = MediaQuery.of(context);
return const SizedBox();
},
child: const SizedBox(),
),
);
},
),
],
),
),
),
);

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

expect(overlayChildData?.padding, expectedPadding);
expect(overlayChildData?.viewInsets, expectedViewInsets);
expect(overlayChildData?.viewPadding, expectedViewPadding);
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This test can be made more robust by better simulating how a Scaffold strips MediaQueryData and by verifying that other MediaQueryData properties are preserved.

Using MediaQuery.of(context).copyWith(...) instead of MediaQueryData(...) ensures that properties from the ambient MediaQuery are inherited, which is closer to how widgets like Scaffold work (they typically use MediaQuery.removePadding).

Additionally, adding checks for other properties like size ensures that the implementation correctly preserves them while only restoring the padding and insets.

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

    MediaQueryData? overlayChildData;

    await tester.pumpWidget(
      MediaQuery(
        data: const MediaQueryData(
          padding: expectedPadding,
          viewInsets: expectedViewInsets,
          viewPadding: expectedViewPadding,
          size: expectedSize,
        ),
        child: Directionality(
          textDirection: TextDirection.ltr,
          child: Overlay(
            initialEntries: <OverlayEntry>[
              OverlayEntry(
                builder: (BuildContext context) {
                  // This MediaQuery simulates a Scaffold stripping the padding away.
                  return MediaQuery(
                    data: MediaQuery.of(context).copyWith(
                      padding: EdgeInsets.zero,
                      viewInsets: EdgeInsets.zero,
                      viewPadding: EdgeInsets.zero,
                    ),
                    child: OverlayPortal(
                      controller: controller,
                      overlayChildBuilder: (BuildContext context) {
                        overlayChildData = MediaQuery.of(context);
                        return const SizedBox();
                      },
                      child: const SizedBox(),
                    ),
                  );
                },
              ),
            ],
          ),
        ),
      ),
    );

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

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

Comment on lines +158 to +162
final OverlayPortalController controller = OverlayPortalController();
final EdgeInsets expectedPadding = EdgeInsets.all(10);
final EdgeInsets expectedViewInsets = EdgeInsets.only(bottom: 300);
final EdgeInsets expectedViewPadding = EdgeInsets.only(top: 50, bottom: 20);
final Size expectedSize = Size(800, 600);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
final OverlayPortalController controller = OverlayPortalController();
final EdgeInsets expectedPadding = EdgeInsets.all(10);
final EdgeInsets expectedViewInsets = EdgeInsets.only(bottom: 300);
final EdgeInsets expectedViewPadding = EdgeInsets.only(top: 50, bottom: 20);
final Size expectedSize = Size(800, 600);
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);

New omit obvious types lint.


await tester.pumpWidget(
MediaQuery(
data: MediaQueryData(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
data: MediaQueryData(
data: const MediaQueryData(

final EdgeInsets expectedViewPadding = EdgeInsets.only(top: 50, bottom: 20);
final Size expectedSize = Size(800, 600);

MediaQueryData? overlayChildData;
Copy link
Contributor

@victorsanni victorsanni Jan 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
MediaQueryData? overlayChildData;
MediaQueryData? overlayChildData;
late final OverlayEntry entry;
addTearDown(() {
entry.remove();
entry.dispose();
});

textDirection: TextDirection.ltr,
child: Overlay(
initialEntries: <OverlayEntry>[
OverlayEntry(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
OverlayEntry(
entry = OverlayEntry(

Copy link
Contributor

@LongCatIsLooong LongCatIsLooong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The approach makes sense to me, except for the way OverlayState is acquired in the PR.

}

MediaQueryData data = MediaQuery.of(context);
final OverlayState? overlay = Overlay.maybeOf(context);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm I don't think this is correct because OverlayPortal can target a different Overlay than it's closest ancestor Overlay.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(could you add a test for this too? I think you can which Overlay to target using https://main-api.flutter.dev/flutter/widgets/OverlayPortal/overlayLocation.html)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch on that one! I have updated the call to Overlay.maybeOf to account for the overlayLocation parameter on the widget. I also added an additional test for this option.

}

MediaQueryData data = MediaQuery.of(context);
final OverlayState? overlay = Overlay.maybeOf(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can get the right context for the Overlay from the _getLocation call instead of looking it up again using Overlay.of.

Copy link
Contributor Author

@patrickBillingsley patrickBillingsley Jan 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just pushed an update. If I understand right, the Overlay.maybeOf call was duplicating what is a potentially cached value in the class. The _OverlayEntryLocation provided by the _getLocation method holds an _OverlayEntryWidgetState which has the necessary context provided from the correct location. This also removes the need for the conditional logic and potential manipulation of the initially fetched MediaQuery from the build method's context.

This should now only have to traverse the tree once to get the correct context based on the overlayLocation.

childIdentifier: this,
child: Builder(builder: widget.overlayChildBuilder),
child: MediaQuery(
data: MediaQuery.of(overlayLocation._childModel.context),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm I think we just want to override the "safe area" related properties on MediaQueryData right? If the developer adds a MediaQuery between an OverlayPortal and its target Overlay (in terms of the widget tree), other overrides on the new MediaQuery like boldText should still be respected should the developer chooses to override them?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are absolutely right.

@justinmc justinmc added the autosubmit Merge PR when tree becomes green via auto submit App label Feb 3, 2026
@auto-submit auto-submit bot added this pull request to the merge queue Feb 3, 2026
Merged via the queue into flutter:master with commit 1e02909 Feb 4, 2026
71 of 72 checks passed
@flutter-dashboard flutter-dashboard bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Feb 4, 2026
auto-submit bot pushed a commit to flutter/packages that referenced this pull request Feb 5, 2026
Roll Flutter from bf701fefec86 to f916dd6887bf (44 revisions)

flutter/flutter@bf701fe...f916dd6

2026-02-05 [email protected] Implement macOS wide gamut (Display P3) support (flutter/flutter#181769)
2026-02-04 [email protected] Roll Skia from d23ecfbfdff9 to 8543ce512d5c (3 revisions) (flutter/flutter#181923)
2026-02-04 [email protected] Roll Dart SDK from 8001c99d952b to 8f778ffd318b (3 revisions) (flutter/flutter#181927)
2026-02-04 [email protected] Re-enable AddressSanitizer on the linux_unopt builder (flutter/flutter#181741)
2026-02-04 [email protected] Add exception to log message in ContentSizingFlag.java (flutter/flutter#181813)
2026-02-04 [email protected] Roll pub packages (flutter/flutter#181925)
2026-02-04 [email protected] [flutter_tools] Deprecate web hot reload flag (flutter/flutter#181884)
2026-02-04 [email protected] Marks platform_views_scroll_perf_impeller__timeline_summary unflaky (flutter/flutter#181649)
2026-02-04 [email protected] Roll Dart SDK from 204db085d970 to 8001c99d952b (1 revision) (flutter/flutter#181902)
2026-02-04 [email protected] Roll Skia from f37a22506eb4 to d23ecfbfdff9 (23 revisions) (flutter/flutter#181915)
2026-02-04 [email protected] In the Web codec tests, skip an undecodable image that is used to test a Skia error handling code path. (flutter/flutter#181870)
2026-02-04 [email protected] Roll Packages from 5b1bea8 to 3bddf2c (5 revisions) (flutter/flutter#181918)
2026-02-04 [email protected] Roll Fuchsia Linux SDK from UmQaaNuhkiuE8Dzug... to J2QdLcY2gyt4NP_xV... (flutter/flutter#181893)
2026-02-04 [email protected] Roll Dart SDK from 54322a0b1109 to 204db085d970 (3 revisions) (flutter/flutter#181890)
2026-02-04 [email protected] Cleanup cross imports (flutter/flutter#181807)
2026-02-04 [email protected] [Material] Remove Material import from backdrop_filter_test.dart widget tests (flutter/flutter#181386)
2026-02-04 [email protected] Move CheckedModeBanner tests to material and remove Material import from widgets banner_test (flutter/flutter#181261)
2026-02-04 [email protected] feat: Pass parameters from DropdownMenuFormField to DropDownMenu (flutter/flutter#181373)
2026-02-04 [email protected] Remove `Config complete` log when using `flutter build apk --config-only` (flutter/flutter#181864)
2026-02-04 [email protected] [Impeller] Fix flattening of very large zoomed curves with tiny stroke widths (flutter/flutter#181505)
2026-02-03 [email protected] Propagates Overlay's MediaQueryData to OverlayPortal child (flutter/flutter#181579)
2026-02-03 [email protected] Make sure that an AnimatedScale doesn't crash in 0x0 environment (flutter/flutter#181481)
2026-02-03 [email protected] Roll Dart SDK from 56294a92d5cc to 54322a0b1109 (1 revision) (flutter/flutter#181872)
2026-02-03 [email protected] Fix decorated box (flutter/flutter#179802)
2026-02-03 [email protected] Roll pub packages (flutter/flutter#181871)
2026-02-03 [email protected] Remove Material library dependency from expansible_test.dart (flutter/flutter#181657)
2026-02-03 [email protected] Organize and update fragment shader uniform tests. (flutter/flutter#181822)
2026-02-03 [email protected] fix(web_ui): handle non-invertible matrices in ImageFilter.matrix (flutter/flutter#181742)
2026-02-03 [email protected] Remove unnecessary Material import from cupertino/slider_test.dart (flutter/flutter#180957)
2026-02-03 [email protected] Remove the Flutter.xcframework as a swift dependency (flutter/flutter#181739)
2026-02-03 [email protected] feature: implementation of tooltips in the `_TestWindowingOwner` and minor bugfixes to the multiple windows example app (flutter/flutter#181510)
2026-02-03 [email protected] [Web] Fix flt-platform-view comment (flutter/flutter#181576)
2026-02-03 [email protected] Marks Linux_pixel_7pro android_verified_input_test to be unflaky (flutter/flutter#179120)
2026-02-03 [email protected] Unmark `hybrid_android_views_integration_test` as bringup (flutter/flutter#181628)
2026-02-03 [email protected] Remove material from sliver_tree_test.dart (flutter/flutter#181415)
2026-02-03 [email protected] Make `android_plugin_new_output_dir_test` only build release (flutter/flutter#181677)
2026-02-03 [email protected] Roll customer tests (flutter/flutter#181825)
2026-02-03 [email protected] Add Linux Foundation Health Score badge to README (flutter/flutter#175587)
2026-02-03 [email protected] Remove unused getters on AndroidProject class (flutter/flutter#181860)
2026-02-03 [email protected] Adds batch release doc for flutter/package (flutter/flutter#181676)
2026-02-03 [email protected] [ Tool ] Don't use `globals.platform` in `getFlutterRoot()` (flutter/flutter#181859)
2026-02-03 [email protected] Roll Packages from 837dbbd to 5b1bea8 (10 revisions) (flutter/flutter#181857)
2026-02-03 [email protected] Remove material from basic_test.dart (flutter/flutter#181444)
2026-02-03 [email protected] [ Tool ] Fix regression introduced in flutter/flutter#181421 (flutter/flutter#181826)

If this roll has caused a breakage, revert this CL and stop the roller
...
github-merge-queue bot pushed a commit that referenced this pull request Feb 5, 2026
Fixes [Autocomplete options overlay should automatically moves up when
soft keyboard is
visible](#157664)
Fixes b/317115348

Unblocked by #181579.

## Before



https://github.com/user-attachments/assets/586944be-6ff1-4817-980e-334bfefb6c62

## After



https://github.com/user-attachments/assets/086f4be9-0ebc-43af-b85b-3435d4144920




<details>
<summary>Sample code</summary>

```dart

import "package:flutter/material.dart";

void main() => runApp(const AutocompleteExampleApp());

/// Flutter code sample for [RawAutocomplete].

class AutocompleteExampleApp extends StatelessWidget {
  const AutocompleteExampleApp({super.key});

  @OverRide
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text("RawAutocomplete Basic"),
        ),
        body: const CustomScrollView(
          slivers: [
            SliverPadding(padding: EdgeInsets.symmetric(vertical: 300)),
            SliverToBoxAdapter(child: AutocompleteBasicExample()),
            SliverPadding(padding: EdgeInsets.symmetric(vertical: 700)),
          ],
        ),
      ),
    );
  }
}

class AutocompleteBasicExample extends StatelessWidget {
  const AutocompleteBasicExample({super.key});

  static const List<String> _options = <String>[
    "aardvark",
    "bobcat",
    "chameleon",
    "chameleon",
  ];

  @OverRide
  Widget build(BuildContext context) {
    return RawAutocomplete<String>(
      optionsBuilder: (TextEditingValue textEditingValue) {
        return _options.where((String option) {
          return option.contains(textEditingValue.text.toLowerCase());
        });
      },
      fieldViewBuilder: (
        BuildContext context,
        TextEditingController textEditingController,
        FocusNode focusNode,
        VoidCallback onFieldSubmitted,
      ) {
        return TextFormField(
          controller: textEditingController,
          focusNode: focusNode,
          onFieldSubmitted: (String value) {
            onFieldSubmitted();
          },
        );
      },
      optionsViewBuilder: (
        BuildContext context,
        AutocompleteOnSelected<String> onSelected,
        Iterable<String> options,
      ) {
        return const Column(
          children: <Widget>[Expanded(child: Placeholder())],
        );
      },
    );
  }
}

```
</details>



## Pre-launch Checklist

- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [x] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [x] I signed the [CLA].
- [x] I listed at least one issue that this PR fixes in the description
above.
- [ ] I updated/added relevant documentation (doc comments with `///`).
- [x] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [x] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [ ] All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel
on [Discord].

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview
[Tree Hygiene]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
[test-exempt]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Discord]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md
[Data Driven Fixes]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md

---------

Co-authored-by: Navaron Bracke <[email protected]>
LongCatIsLooong pushed a commit to LongCatIsLooong/flutter that referenced this pull request Feb 6, 2026
…81579)

Widgets like Scaffold strip MediaQueryData causing widgets rendered in
the Overlay to be obscured, e.g., by the software keyboard.

[Related Issue -
142921](flutter#142921)
[Related Issue -
157664](flutter#157664)

This does not directly fix these two issues but appears to be an
underlying issue with both which merited this being a separate PR. I
have a separate fix for the MenuAnchor that I will supply in a follow up
PR.

## Pre-launch Checklist

- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [x] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [x] I signed the [CLA].
- [x] I listed at least one issue that this PR fixes in the description
above.
- [ ] I updated/added relevant documentation (doc comments with `///`).
- [x] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [x] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [x] All existing and new tests are passing.

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview
[Tree Hygiene]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
[test-exempt]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Discord]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md
[Data Driven Fixes]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
flutter-zl pushed a commit to flutter-zl/flutter that referenced this pull request Feb 10, 2026
…81579)

Widgets like Scaffold strip MediaQueryData causing widgets rendered in
the Overlay to be obscured, e.g., by the software keyboard.

[Related Issue -
142921](flutter#142921)
[Related Issue -
157664](flutter#157664)

This does not directly fix these two issues but appears to be an
underlying issue with both which merited this being a separate PR. I
have a separate fix for the MenuAnchor that I will supply in a follow up
PR.

## Pre-launch Checklist

- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [x] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [x] I signed the [CLA].
- [x] I listed at least one issue that this PR fixes in the description
above.
- [ ] I updated/added relevant documentation (doc comments with `///`).
- [x] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [x] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [x] All existing and new tests are passing.

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview
[Tree Hygiene]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
[test-exempt]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Discord]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md
[Data Driven Fixes]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
flutter-zl pushed a commit to flutter-zl/flutter that referenced this pull request Feb 10, 2026
Fixes [Autocomplete options overlay should automatically moves up when
soft keyboard is
visible](flutter#157664)
Fixes b/317115348

Unblocked by flutter#181579.

## Before



https://github.com/user-attachments/assets/586944be-6ff1-4817-980e-334bfefb6c62

## After



https://github.com/user-attachments/assets/086f4be9-0ebc-43af-b85b-3435d4144920




<details>
<summary>Sample code</summary>

```dart

import "package:flutter/material.dart";

void main() => runApp(const AutocompleteExampleApp());

/// Flutter code sample for [RawAutocomplete].

class AutocompleteExampleApp extends StatelessWidget {
  const AutocompleteExampleApp({super.key});

  @OverRide
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text("RawAutocomplete Basic"),
        ),
        body: const CustomScrollView(
          slivers: [
            SliverPadding(padding: EdgeInsets.symmetric(vertical: 300)),
            SliverToBoxAdapter(child: AutocompleteBasicExample()),
            SliverPadding(padding: EdgeInsets.symmetric(vertical: 700)),
          ],
        ),
      ),
    );
  }
}

class AutocompleteBasicExample extends StatelessWidget {
  const AutocompleteBasicExample({super.key});

  static const List<String> _options = <String>[
    "aardvark",
    "bobcat",
    "chameleon",
    "chameleon",
  ];

  @OverRide
  Widget build(BuildContext context) {
    return RawAutocomplete<String>(
      optionsBuilder: (TextEditingValue textEditingValue) {
        return _options.where((String option) {
          return option.contains(textEditingValue.text.toLowerCase());
        });
      },
      fieldViewBuilder: (
        BuildContext context,
        TextEditingController textEditingController,
        FocusNode focusNode,
        VoidCallback onFieldSubmitted,
      ) {
        return TextFormField(
          controller: textEditingController,
          focusNode: focusNode,
          onFieldSubmitted: (String value) {
            onFieldSubmitted();
          },
        );
      },
      optionsViewBuilder: (
        BuildContext context,
        AutocompleteOnSelected<String> onSelected,
        Iterable<String> options,
      ) {
        return const Column(
          children: <Widget>[Expanded(child: Placeholder())],
        );
      },
    );
  }
}

```
</details>



## Pre-launch Checklist

- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [x] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [x] I signed the [CLA].
- [x] I listed at least one issue that this PR fixes in the description
above.
- [ ] I updated/added relevant documentation (doc comments with `///`).
- [x] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [x] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [ ] All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel
on [Discord].

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview
[Tree Hygiene]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
[test-exempt]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Discord]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md
[Data Driven Fixes]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md

---------

Co-authored-by: Navaron Bracke <[email protected]>
rickhohler pushed a commit to rickhohler/flutter that referenced this pull request Feb 19, 2026
…81579)

Widgets like Scaffold strip MediaQueryData causing widgets rendered in
the Overlay to be obscured, e.g., by the software keyboard.

[Related Issue -
142921](flutter#142921)
[Related Issue -
157664](flutter#157664)

This does not directly fix these two issues but appears to be an
underlying issue with both which merited this being a separate PR. I
have a separate fix for the MenuAnchor that I will supply in a follow up
PR.

## Pre-launch Checklist

- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [x] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [x] I signed the [CLA].
- [x] I listed at least one issue that this PR fixes in the description
above.
- [ ] I updated/added relevant documentation (doc comments with `///`).
- [x] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [x] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [x] All existing and new tests are passing.

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview
[Tree Hygiene]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
[test-exempt]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Discord]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md
[Data Driven Fixes]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
rickhohler pushed a commit to rickhohler/flutter that referenced this pull request Feb 19, 2026
Fixes [Autocomplete options overlay should automatically moves up when
soft keyboard is
visible](flutter#157664)
Fixes b/317115348

Unblocked by flutter#181579.

## Before



https://github.com/user-attachments/assets/586944be-6ff1-4817-980e-334bfefb6c62

## After



https://github.com/user-attachments/assets/086f4be9-0ebc-43af-b85b-3435d4144920




<details>
<summary>Sample code</summary>

```dart

import "package:flutter/material.dart";

void main() => runApp(const AutocompleteExampleApp());

/// Flutter code sample for [RawAutocomplete].

class AutocompleteExampleApp extends StatelessWidget {
  const AutocompleteExampleApp({super.key});

  @OverRide
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text("RawAutocomplete Basic"),
        ),
        body: const CustomScrollView(
          slivers: [
            SliverPadding(padding: EdgeInsets.symmetric(vertical: 300)),
            SliverToBoxAdapter(child: AutocompleteBasicExample()),
            SliverPadding(padding: EdgeInsets.symmetric(vertical: 700)),
          ],
        ),
      ),
    );
  }
}

class AutocompleteBasicExample extends StatelessWidget {
  const AutocompleteBasicExample({super.key});

  static const List<String> _options = <String>[
    "aardvark",
    "bobcat",
    "chameleon",
    "chameleon",
  ];

  @OverRide
  Widget build(BuildContext context) {
    return RawAutocomplete<String>(
      optionsBuilder: (TextEditingValue textEditingValue) {
        return _options.where((String option) {
          return option.contains(textEditingValue.text.toLowerCase());
        });
      },
      fieldViewBuilder: (
        BuildContext context,
        TextEditingController textEditingController,
        FocusNode focusNode,
        VoidCallback onFieldSubmitted,
      ) {
        return TextFormField(
          controller: textEditingController,
          focusNode: focusNode,
          onFieldSubmitted: (String value) {
            onFieldSubmitted();
          },
        );
      },
      optionsViewBuilder: (
        BuildContext context,
        AutocompleteOnSelected<String> onSelected,
        Iterable<String> options,
      ) {
        return const Column(
          children: <Widget>[Expanded(child: Placeholder())],
        );
      },
    );
  }
}

```
</details>



## Pre-launch Checklist

- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [x] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [x] I signed the [CLA].
- [x] I listed at least one issue that this PR fixes in the description
above.
- [ ] I updated/added relevant documentation (doc comments with `///`).
- [x] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [x] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [ ] All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel
on [Discord].

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview
[Tree Hygiene]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
[test-exempt]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Discord]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md
[Data Driven Fixes]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md

---------

Co-authored-by: Navaron Bracke <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants