Skip to content

Software Development at Program Tom LTD

Place for coding, programming, development and software in general.

Menu
  • Blog
  • PDF Booklets
  • Dev Utils & Content
  • Java Spring Boot Or Web Apps
  • English
    • български
    • English
    • Español
    • Português
    • हिन्दी
    • Русский
    • Deutsch
    • Français
    • Italiano
    • العربية
  • About Us
Menu
how to insert padding in flutter - to ensure visibility - when the keyboard is visible

How to insert padding in Flutter – to ensure visibility – when the Keyboard is Visible

Posted on November 19, 2025November 19, 2025 by Toma Velev

In Flutter, when the keyboard appears (especially on mobile), it often covers the bottom part of the screen, hiding your TextField or buttons. To automatically add padding at the bottom when the keyboard is visible — and ensure your input field stays visible above the keyboard — here are the best and most common solutions:

Recommended Solution (2025 best practice): Use scaffoldResizeToAvoidBottomInset + Padding with MediaQuery.viewInsets

Wrap your main content (or just the input area) with padding that reacts to the keyboard:

import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        resizeToAvoidBottomInset: true, // This is important!
        body: MyHomePage(),
      ),
    );
  }
}

class MyHomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return SafeArea(
      child: Padding(
        // This padding will automatically grow when keyboard appears
        padding: EdgeInsets.only(
          bottom: MediaQuery.of(context).viewInsets.bottom,
        ),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.end, // Push content to bottom
          children: [
            // Your other widgets...

            TextField(
              decoration: InputDecoration(
                labelText: "Enter text",
                border: OutlineInputBorder(),
              ),
            ),

            SizedBox(height: 20),

            ElevatedButton(
              onPressed: () {},
              child: Text("Submit"),
            ),

            SizedBox(height: 20), // Extra space so it doesn't stick to edge
          ],
        ),
      ),
    );
  }
}

Why this works perfectly:

  • MediaQuery.of(context).viewInsets.bottom → returns the height of the keyboard (or 0 when hidden)
  • resizeToAvoidBottomInset: true → allows the Scaffold to shrink when keyboard appears
  • The Padding automatically pushes your content up exactly by the keyboard height
  • Works perfectly with Column + mainAxisAlignment: MainAxisAlignment.end

Alternative: Use SingleChildScrollView (for longer forms)

If your form is long and might need scrolling:

Scaffold(
  resizeToAvoidBottomInset: false, // Set to false when using manual scroll
  body: SafeArea(
    child: SingleChildScrollView(
      padding: EdgeInsets.only(
        left: 16,
        right: 16,
        bottom: MediaQuery.of(context).viewInsets.bottom + 20,
      ),
      child: Column(
        children: [
          // Many TextFields...
          TextField(...),
          TextField(...),
          // ...
          SizedBox(height: 20),
          ElevatedButton(onPressed: () {}, child: Text("Submit")),
        ],
      ),
    ),
  ),
)

Bonus: Auto-scroll to focused field (optional but nice)

Add scrollPadding to your TextField:

TextField(
  scrollPadding: EdgeInsets.only(bottom: 200), // Extra space when keyboard opens
  decoration: InputDecoration(...),
)

Or use the flutter_keyboard_visibility package if you want to react to keyboard show/hide events explicitly.

Summary – Quick Copy-Paste Fix

Just add this to your Scaffold body:

padding: EdgeInsets.only(bottom: MediaQuery.of(context).viewInsets.bottom),

and make sure:

Scaffold(
  resizeToAvoidBottomInset: true, // almost always want this
  ...
)

This is the standard, cleanest, and most reliable way in Flutter as of 2025.


@override
void didChangeMetrics() {
// Called when viewInsets (like keyboard height) changes
final bottomInset = WidgetsBinding.instance.window.viewInsets.bottom;
final newValue = bottomInset > 0.0;
if (newValue != _isKeyboardVisible) {
setState(() => _isKeyboardVisible = newValue);
}
}

if (_isKeyboardVisible)
Widget(...),
  • Prompt-to-Production: How AI is Forcing Us to Build Higher Quality Software
  • Debug Web View Flutter App
  • Skipping AI? You’re a Relic – Time to Evolve or Perish!
  • 2026 Flutter Launch Blueprint: Your 10-Step Checklist to App Store Domination
  • Product Requirements Document – for different software development levels

Categories

  • Apps (25)
  • ChatGPT (27)
  • Choosing a Framework (38)
  • Flutter (281)
  • Graphical User Interface (14)
  • Marketing (119)
  • Software Development (292)
  • Spring (45)
  • StartUp (22)
  • Uncategorized (14)
  • Uncategorized (4)
  • Vaadin (16)

Tags

Algorithms (9) crypto (29) flutterdev (39) General (86) Java (7) QR & Bar Codes (3) Software Dev Choices (33) Spring Boot (1) standards (1) Theme (3) User Authentication & Authorization (9) User Experience (10) Utilities (19) WordPress (11)

Product categories

  • All Technologies (87)
    • Flutter Apps (26)
    • GPT (4)
    • Java (39)
    • Native Android (3)
    • PHP (9)
    • Spring (Boot) / Quarkus (36)
    • Utils (15)
    • Vaadin 24+ (28)
    • Vaadin 8 (1)
  • Apps (18)
    • Employees DB (1)
    • Notes (6)
    • Personal Budget (1)
    • Recipes Book (1)
    • Stuff Organizer (1)
    • To-Do (2)
  • PDF Books (3)
  • Source Code Generators (8)

Recent Posts

  • Prompt-to-Production: How AI is Forcing Us to Build Higher Quality Software
  • Debug Web View Flutter App
  • Skipping AI? You’re a Relic – Time to Evolve or Perish!
  • 2026 Flutter Launch Blueprint: Your 10-Step Checklist to App Store Domination
  • Product Requirements Document – for different software development levels

Post Categories

  • Apps (25)
  • ChatGPT (27)
  • Choosing a Framework (38)
  • Flutter (281)
  • Graphical User Interface (14)
  • Marketing (119)
  • Software Development (292)
  • Spring (45)
  • StartUp (22)
  • Uncategorized (14)
  • Uncategorized (4)
  • Vaadin (16)