What is resizeToAvoidBottomInset? When should we use it?
#widget#keyboard#scaffold
Answer
Overview
is a textresizeToAvoidBottomInset
text
Scaffoldtext
trueHow It Works
textWithout keyboard: ┌──────────────────┐ │ AppBar │ │ │ │ Body Content │ │ │ │ TextField ←─────┼── cursor here └──────────────────┘ When keyboard opens (resizeToAvoidBottomInset: true): ┌──────────────────┐ │ AppBar │ │ Body Content │ ← body shrinks │ TextField │ ← stays visible └──────────────────┘ │ KEYBOARD │ └──────────────────┘
Default Behavior (true)
dartScaffold( resizeToAvoidBottomInset: true, // Default body: Column( children: [ Expanded(child: ListView(...)), TextField(decoration: InputDecoration(labelText: 'Message')), ], ), ) // Body shrinks when keyboard appears — TextField always visible
Disabled (false)
dartScaffold( 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
| Situation | Set to text |
|---|---|
| Full-screen backgrounds/images that shouldn't resize | ✅ |
| Custom keyboard handling using text | ✅ |
| 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
for most screens. Set it totextresizeToAvoidBottomInset: truewhen you have full-screen backgrounds or need custom keyboard handling with atextfalselayout.textStack