Migration to Flutter Guide
Discover our battle-tested 21-step framework for a smooth and successful migration to Flutter!
Jump to:

Dialogs in Flutter

What are dialogs in Flutter?

Dialogs in Flutter are modal UI elements used to display information, ask for confirmation, or collect a small amount of input. They appear above the current screen and block interaction with the background until closed.

Common examples include AlertDialog, SimpleDialog, and custom dialogs built with Dialog.

How do dialogs work?

Dialogs are shown using showDialog, which pushes a new route onto the navigation stack. Because of this, a dialog is not part of the widget tree of the current screen.

Important consequences:

  • Dialogs live on a separate route.
  • They return a Future<T?>.
  • Rebuilding the parent widget does not rebuild the dialog.

Example:

final result = await showDialog<bool>(
  context: context,
  builder: (context) => AlertDialog(
    title: const Text('Confirm'),
    actions: [
      TextButton(
        onPressed: () => Navigator.pop(context, false),
        child: const Text('Cancel'),
      ),
      TextButton(
        onPressed: () => Navigator.pop(context, true),
        child: const Text('OK'),
      ),
    ],
  ),
);

Why do dialogs matter in Flutter app development?

Dialogs are often used for destructive or critical actions. Incorrect handling can cause:

  • UI that does not update.
  • Lost user input.
  • Unexpected null results.

Understanding their lifecycle is essential for building reliable user flows.

When to use dialogs?

Dialogs are a good choice when:

  • user confirmation is required (delete, logout)
  • showing short blocking information
  • collecting minimal input (checkbox, single field)

They should stay simple and focused.

When not to use dialogs?

Avoid dialogs when:

  • Content is complex or requires extensive scrolling.
  • Long interaction is required.
  • State must persist for a long time.

In such cases, prefer bottom sheets or full screens.

Common dialog implementation pitfalls

Some issues appear very frequently:

  • Calling setState in the parent: setState does not update an open dialog because it lives on a different route.
  • Expecting dialogs to keep state: Once closed, all dialog state is destroyed.
  • Ignoring null results: Clicking outside the dialog returns null by default.
  • Using platform-specific styles manually: Hardcoding styles leads to duplicated code and inconsistent UI.

Best practices for dialog management

To avoid common problems:

  • Updating state inside a dialog: Wrap the dialog content in StatefulBuilder or extract it into a separate StatefulWidget if UI inside the dialog must change (e.g. checkbox, counter).
  • Returning data explicitly: Always close dialogs with Navigator.pop(context, value) and read the result using await showDialog.
  • Handling critical actions: Use barrierDismissible: false to prevent closing the dialog by tapping outside.
  • Supporting iOS and Android: Use AlertDialog.adaptive to automatically match Material and Cupertino styles.

Dialogs are powerful, but only when their routing and state behavior are fully understood.

Learn more

Design system Flutter

Building a Design System in a Large Flutter App

Flutter is known for its seamless UI/UX features and robust design elements. It allowed us to deliver a unique customer experience in the “CA24 Mobile” banking app. This article shares some of the learnings and pain points behind implementing it in this large project.

accessibility in web design

Essential Accessibility: How to Lower the Cost of Building Accessible Web

Most digital products fail to address the rising needs of users with impairments. One of the reasons why business owners don’t decide to implement accessibility standards is a concern that it may raise the cost of web development. Read how to improve web and web app accessibility at a low cost.