Coding⏱️ 3 min read📅 2026-06-03

How to Fix: How to Move bottomsheet along with keyboard which has textfield(autofocused is true)?

Move bottomsheet above keyboard with autofocus.

Quick Answer: Use the `showModalBottomSheet` method and set `isScrollControlled: true` to allow scrolling. Then, use `FocusScope` to focus on the first child widget of the modal bottom sheet.

The issue you are facing is when you try to display a bottomsheet with a text field and autofocus enabled, but it gets overlapped by the keyboard. This can be frustrating as it prevents the text field from receiving focus.

To resolve this issue, we will explore two methods: using the `showModalBottomSheet` function with the `isScrollControlled` parameter set to true, or using a workaround with the `OverlayEntry` class.

⚠️ Common Causes

  • The root cause of this issue is that the bottomsheet is not designed to handle keyboard input. When the keyboard appears, it pushes the bottomsheet up, causing overlap.
  • Another possible reason is that the text field's autofocus property is not being respected due to the overlay of the keyboard.

🚀 How to Resolve This Issue

Method 1: Using showModalBottomSheet with isScrollControlled

  1. Step 1: Create a new function to display the bottomsheet with the text field and autofocus enabled.
  2. Step 2: Use the `showModalBottomSheet` function with the `isScrollControlled` parameter set to true to ensure the keyboard does not overlap the bottomsheet.
  3. Step 3: Pass the `TextField` widget as a child to the `modalBottomSheetBuilder` property of the `showModalBottomSheet` function.

Method 2: Workaround using OverlayEntry

  1. Step 1: Create an instance of the `OverlayEntry` class.
  2. Step 2: Use the `overlayEntry` parameter to set the position of the overlay entry above the bottomsheet.
  3. Step 3: Pass the `TextField` widget as a child to the `overlayEntry` parameter.

✨ Wrapping Up

By using either method, you should be able to display the bottomsheet with the text field and autofocus enabled without any overlap issues.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions