Question #335MediumWidgets & UI

What is resizeToAvoidBottomInset? When should we use it?

#widget#keyboard#scaffold

Answer

Overview

text
resizeToAvoidBottomInset
is a
text
Scaffold
property that controls whether the body resizes when the soft keyboard appears. When
text
true
(the default), the Scaffold body shrinks up to avoid being covered by the keyboard.


How It Works

text
Without keyboard:
┌──────────────────┐
│ AppBar           │
│                  │
│   Body Content   │
│                  │
│ TextField  ←─────┼── cursor here
└──────────────────┘

When keyboard opens (resizeToAvoidBottomInset: true):
┌──────────────────┐
│ AppBar           │
│   Body Content   │ ← body shrinks
│ TextField        │ ← stays visible
└──────────────────┘
│   KEYBOARD       │
└──────────────────┘

Default Behavior (true)

dart
Scaffold(
  resizeToAvoidBottomInset: true, // Default
  body: Column(
    children: [
      Expanded(child: ListView(...)),
      TextField(decoration: InputDecoration(labelText: 'Message')),
    ],
  ),
)
// Body shrinks when keyboard appears — TextField always visible

Disabled (false)

dart
Scaffold(
  resizeToAvoidBottomInset: false,
  body: Stack(
    children: [
      // Background image — should not resize
      Positioned.fill(child: Image.asset('bg.jpg', fit: BoxFit.cover)),
      // Form positioned above keyboard manually
      Positioned(
        bottom: MediaQuery.of(context).viewInsets.bottom + 16,
        left: 16, right: 16,
        child: TextField(),
      ),
    ],
  ),
)

When to Set to false

SituationSet to
text
false
Full-screen backgrounds/images that shouldn't resize
Custom keyboard handling using
text
MediaQuery.viewInsets
Chat input bars at bottom of screen✅ (handle manually)
Login screens with background images

Manual Keyboard Padding (when false)

dart
// Manually add padding equal to keyboard height
Padding(
  padding: EdgeInsets.only(
    bottom: MediaQuery.of(context).viewInsets.bottom,
  ),
  child: TextField(),
)

Default: Leave

text
resizeToAvoidBottomInset: true
for most screens. Set it to
text
false
when you have full-screen backgrounds or need custom keyboard handling with a
text
Stack
layout.