If you've ever built a form inside a bottom sheet in Flutter, there's a good chance you've hit this wall: the keyboard pops up, and suddenly half your UI disappears behind it. Input fields become unreachable, users get frustrated, and your polish takes a hit.
This is one of those Flutter gotchas that bites almost every developer at least once. The good news? The fix is elegant and takes less than a minute to implement.
The Problem: Bottom Sheet Doesn't Account for the Keyboard
By default, Flutter's showModalBottomSheet doesn't automatically adjust its layout when the software keyboard appears. The sheet stays at its original position, and the keyboard simply renders on top of it.
This results in:
- Input fields hidden behind the keyboard
- Users unable to see what they're typing
- A frustrating form interaction that kills the experience
The root cause is that showModalBottomSheet uses isScrollControlled: false by default, which means the sheet height is fixed and unaware of the keyboard inset.
The Clean Solution: viewInsets.bottom as Padding
The most elegant fix is to use MediaQuery.of(context).viewInsets.bottom as dynamic bottom padding on your content. This gives you the exact pixel height of the visible keyboard and uses it to push your content up — automatically.
Padding( padding: EdgeInsets.only( bottom: MediaQuery.of(context).viewInsets.bottom, ), child: Column( mainAxisSize: MainAxisSize.min, children: [ TextField(), TextField(), ], ),)
No extra spacers. No hardcoded heights. Just a single property that adapts to whatever the keyboard is doing.