Skip to content

Constrain RawAutocomplete options by soft keyboard#181930

Merged
auto-submit[bot] merged 8 commits intomasterfrom
autocomplete-keyboard
Feb 5, 2026
Merged

Constrain RawAutocomplete options by soft keyboard#181930
auto-submit[bot] merged 8 commits intomasterfrom
autocomplete-keyboard

Conversation

@victorsanni
Copy link
Contributor

@victorsanni victorsanni commented Feb 4, 2026

Fixes Autocomplete options overlay should automatically moves up when soft keyboard is visible
Fixes b/317115348

Unblocked by #181579.

Before

before.soft.keyboard.mov

After

Screen.Recording.2025-02-28.at.4.04.29.PM.mov
Sample code
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())],
        );
      },
    );
  }
}

Pre-launch Checklist

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

@github-actions github-actions bot added the framework flutter/packages/flutter repository. See also f: labels. label Feb 4, 2026
@victorsanni
Copy link
Contributor Author

Continuation of #163868

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 constrains the RawAutocomplete options view by the soft keyboard and other system insets by using MediaQueryData.viewInsets and MediaQueryData.padding. The implementation in autocomplete.dart is clean and the added tests in autocomplete_test.dart are thorough. I have a few suggestions to simplify the new tests for better clarity and efficiency.

Comment on lines +3742 to +3744
await tester.tap(find.byType(TextField));
await tester.enterText(find.byType(TextField), 'abc');
await tester.pump();
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

Similar to the previous comment, these lines appear to be unnecessary. After updating tester.view.viewInsets and calling await tester.pump(), the overlay should have already been relaid out with the new constraints. The extra tap and text entry can be removed to simplify the test.

Copy link
Contributor

@justinmc justinmc left a comment

Choose a reason for hiding this comment

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

LGTM 👍. Thanks for following up on this! What was the change that made this possible, out of curiosity?

Is there any reason to allow users to opt into the old behavior, or is it definitely not desirable behavior?

Copy link
Contributor

@Piinks Piinks left a comment

Choose a reason for hiding this comment

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

This also LGTM with the nit regarding paddingOf

@victorsanni
Copy link
Contributor Author

Thanks for following up on this! What was the change that made this possible, out of curiosity?

#181579, adding to PR description.

Is there any reason to allow users to opt into the old behavior, or is it definitely not desirable behavior?

Definitely not desirable, currently options can't be tapped when hidden behind the keyboard, this PR fixes that.

@victorsanni
Copy link
Contributor Author

Scuba changes are expected.

@victorsanni victorsanni added the autosubmit Merge PR when tree becomes green via auto submit App label Feb 5, 2026
@auto-submit auto-submit bot added this pull request to the merge queue Feb 5, 2026
Merged via the queue into master with commit 153301a Feb 5, 2026
78 checks passed
@auto-submit auto-submit bot deleted the autocomplete-keyboard branch February 5, 2026 23:16
@flutter-dashboard flutter-dashboard bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Feb 5, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 6, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 6, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 7, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 7, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 8, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 8, 2026
auto-submit bot pushed a commit to flutter/packages that referenced this pull request Feb 8, 2026
Roll Flutter from f916dd6887bf to e8f9dc50356d (34 revisions)

flutter/flutter@f916dd6...e8f9dc5

2026-02-08 [email protected] Roll Skia from 9325111e6ee4 to b7db9f35f0f2 (1 revision) (flutter/flutter#182062)
2026-02-08 [email protected] Roll Skia from 3167229206b5 to 9325111e6ee4 (1 revision) (flutter/flutter#182061)
2026-02-08 [email protected] Roll Fuchsia Linux SDK from sYqpDF9l9-kldd9_Q... to iqtwdXlgKIyZkL5Li... (flutter/flutter#182058)
2026-02-08 [email protected] Roll Skia from ae78024b261e to 3167229206b5 (1 revision) (flutter/flutter#182055)
2026-02-07 [email protected] Roll Dart SDK from ad6368edbe02 to 965b51c219d3 (1 revision) (flutter/flutter#182050)
2026-02-07 [email protected] Roll Skia from a471f253b941 to ae78024b261e (1 revision) (flutter/flutter#182049)
2026-02-07 [email protected] Roll Fuchsia Linux SDK from IOzzhWfhdzhu3zHsz... to sYqpDF9l9-kldd9_Q... (flutter/flutter#182043)
2026-02-07 [email protected] Roll Dart SDK from 02092faa97c5 to ad6368edbe02 (2 revisions) (flutter/flutter#182040)
2026-02-07 [email protected] Roll Skia from 9a983f6c2c06 to a471f253b941 (24 revisions) (flutter/flutter#182039)
2026-02-07 [email protected] Add buffer around rerasterized input to fragment shaders to maintain coordinate space when clipped (flutter/flutter#181743)
2026-02-07 [email protected] Update Flutter's style guide for dot shorthands and extension methods (flutter/flutter#181934)
2026-02-06 [email protected] Manual roll Skia from 39aa2a70213a to 9a983f6c2c06 (flutter/flutter#181986)
2026-02-06 [email protected] Update doc in foundation to match the style guide (flutter/flutter#181972)
2026-02-06 [email protected] Roll Dart SDK from ec674bdb3ae4 to 02092faa97c5 (11 revisions) (flutter/flutter#182017)
2026-02-06 [email protected] Roll Packages from c197455 to 7805d3e (4 revisions) (flutter/flutter#182016)
2026-02-06 98614782+auto-submit[bot]@users.noreply.github.com Reverts "[cupertino.dart] Implement CupertinoMenuAnchor and CupertinoMenuItem using RawMenuAnchor (#174695)" (flutter/flutter#182010)
2026-02-06 [email protected] Update Dart SDK to 3.12 beta1 (flutter/flutter#181948)
2026-02-06 [email protected] [cupertino.dart] Implement CupertinoMenuAnchor and CupertinoMenuItem using RawMenuAnchor (flutter/flutter#174695)
2026-02-06 [email protected] `flutter_tool` : Remove redundant enum types inside the enum definition scope (flutter/flutter#181910)
2026-02-06 [email protected] Roll pub packages (flutter/flutter#181973)
2026-02-05 [email protected] Roll Fuchsia Linux SDK from J2QdLcY2gyt4NP_xV... to IOzzhWfhdzhu3zHsz... (flutter/flutter#181971)
2026-02-05 [email protected] Directly generate a Mach-O dynamic library using gen_snapshot. [reland] (flutter/flutter#181539)
2026-02-05 [email protected] macOS: Implement tooltip window controller (flutter/flutter#180895)
2026-02-05 [email protected] Constrain RawAutocomplete options by soft keyboard (flutter/flutter#181930)
2026-02-05 [email protected] Roll Skia from 079d092f49e6 to 39aa2a70213a (1 revision) (flutter/flutter#181970)
2026-02-05 [email protected] perf: web ui loadFontFromList (flutter/flutter#181440)
2026-02-05 [email protected] Improve accessibility contrast for pre-test message (flutter/flutter#180469)
2026-02-05 [email protected] Roll pub packages (flutter/flutter#181965)
2026-02-05 [email protected] Roll Skia from 8543ce512d5c to 079d092f49e6 (8 revisions) (flutter/flutter#181964)
2026-02-05 [email protected] Add `clearError` API to Form and FormFieldState (flutter/flutter#180752)
2026-02-05 [email protected] Bump minimum required Xcode version to 15 and recommended to 16 (flutter/flutter#180531)
2026-02-05 [email protected] Rename "widgetTester" parameter to "tester" in "WidgetTesterCallback" (flutter/flutter#180944)
2026-02-05 [email protected] Roll Packages from 3bddf2c to c197455 (3 revisions) (flutter/flutter#181962)
2026-02-05 [email protected] Temporarily remove the Pixel 9/API 36 device from the Firebase Test Lab tests. (flutter/flutter#181956)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages
Please CC [email protected] on the revert to ensure that a human
is aware of the problem.

To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

...
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
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.

Autocomplete options overlay should automatically moves up when soft keyboard is visible

5 participants