A wrapper on top of alert dialog provided by flutter.

Overview

material_dialog

A wrapper on top of alert dialog provided by flutter.

Demo

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

dependencies:
  material_dialog: ^0.0.x

2. Install it

You can install packages from the command line:

with Flutter

$ flutter packages get

Alternatively, your editor might support flutter packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:material_dialog/material_dialog.dart';

How to use

Using Material Dialog is quite easy, all you need to do is

MaterialDialog(
  content: Text(_alertText),
  actions: <Widget>[
    FlatButton(
      child: Text(
        'CANCEL',
        style: Theme.of(context).textTheme.button.copyWith(
            fontSize: 12.0, color: Theme.of(context).primaryColor),
      ),
      onPressed: () {
        Navigator.pop(context, DialogDemoAction.agree);
      },
    ),
    FlatButton(
      child: Text(
        'OK',
        style: Theme.of(context).textTheme.button.copyWith(
            fontSize: 12.0, color: Theme.of(context).primaryColor),
      ),
      onPressed: () {
        Navigator.pop(context, DialogDemoAction.cancel);
      },
    ),
  ],
);

Use below method to show dialog

  void showDemoDialog<T>({BuildContext context, Widget child}) {
    showDialog<T>(
      context: context,
      builder: (BuildContext context) => child,
    ).then<void>((T value) {
      // The value passed to Navigator.pop() or null.
      if (value != null) {
        _scaffoldKey.currentState.showSnackBar(SnackBar(
          content: Text('You selected: $value'),
        ));
      }
    });
  }

Simple Alert Dialog

Widget _buildAlertDialog(ThemeData theme, BuildContext context) {
return MaterialDialog(
  content: Text(_alertText),
  actions: <Widget>[
    FlatButton(
      child: Text(
        'CANCEL',
        style: Theme.of(context).textTheme.button.copyWith(
            fontSize: 12.0, color: Theme.of(context).primaryColor),
      ),
      onPressed: () {
        Navigator.pop(context, DialogDemoAction.agree);
      },
    ),
    FlatButton(
      child: Text(
        'OK',
        style: Theme.of(context).textTheme.button.copyWith(
            fontSize: 12.0, color: Theme.of(context).primaryColor),
      ),
      onPressed: () {
        Navigator.pop(context, DialogDemoAction.cancel);
      },
    ),
  ],
);
}

Alert Dialog With Title

Widget _buildAlertDialogWithTitle(ThemeData theme, BuildContext context) {
return MaterialDialog(
  title: Text(_alertTitle),
  subTitle: Text('Subtitle'),
  content: Text(_alertText),
  actions: <Widget>[
    FlatButton(
      child: Text(
        'CANCEL',
        style: Theme.of(context).textTheme.button.copyWith(
            fontSize: 12.0, color: Theme.of(context).primaryColor),
      ),
      onPressed: () {
        Navigator.pop(context, DialogDemoAction.agree);
      },
    ),
    FlatButton(
      child: Text(
        'OK',
        style: Theme.of(context).textTheme.button.copyWith(
            fontSize: 12.0, color: Theme.of(context).primaryColor),
      ),
      onPressed: () {
        Navigator.pop(context, DialogDemoAction.cancel);
      },
    ),
  ],
);
}

Alert Dialog With Close & Back Button

Widget _buildAlertDialogWithCloseAndBackButton(
  ThemeData theme, BuildContext context) {
return MaterialDialog(
  title: Text(_alertTitle),
  subTitle: Text('Subtitle'),
  content: Text(_alertText),
  enableBackButton: true,
  enableCloseButton: true,
  onBackButtonClicked: () {
    Navigator.pop(context, DialogDemoAction.agree);
  },
  onCloseButtonClicked: () {
    Navigator.pop(context, DialogDemoAction.cancel);
  },
  actions: <Widget>[
    FlatButton(
      child: Text(
        'CANCEL',
        style: Theme.of(context).textTheme.button.copyWith(
            fontSize: 12.0, color: Theme.of(context).primaryColor),
      ),
      onPressed: () {
        Navigator.pop(context, DialogDemoAction.agree);
      },
    ),
    FlatButton(
      child: Text(
        'OK',
        style: Theme.of(context).textTheme.button.copyWith(
            fontSize: 12.0, color: Theme.of(context).primaryColor),
      ),
      onPressed: () {
        Navigator.pop(context, DialogDemoAction.cancel);
      },
    ),
  ],
);
}

Alert Dialog With Children

Widget _buildAlertDialogWithChildren(
  ThemeData theme, BuildContext context, bool isFullScreen) {
return MaterialDialog(
  borderRadius: 8.0,
  enableFullHeight: isFullScreen,
  enableFullWidth: isFullScreen,
  enableCloseButton: true,
  closeButtonColor: Colors.white,
  headerColor: Theme.of(context).primaryColor,
  title: Text(
    _alertTitle,
    style: TextStyle(
      color: Colors.white,
      fontSize: 18.0,
    ),
  ),
  subTitle: Text(
    'Subtitle',
    style: TextStyle(
      color: Colors.white70,
      fontSize: 12.0,
    ),
  ),
  onCloseButtonClicked: () {
    Navigator.pop(context, DialogDemoAction.cancel.toString());
  },
  children: <Widget>[
    Text(
      _alertTitle,
      style: TextStyle(
        fontSize: 18.0,
      ),
    ),
    SizedBox(height: 8.0),
    Text(
      _alertText,
      style: TextStyle(
        fontSize: 12.0,
      ),
    ),
    SizedBox(height: 16.0),
    TextField(
      decoration: InputDecoration(hintText: 'Enter Username'),
    ),
  ],
  actions: <Widget>[
    FlatButton(
      child: Text(
        'CANCEL',
        style: Theme.of(context).textTheme.button.copyWith(
            fontSize: 12.0, color: Theme.of(context).primaryColor),
      ),
      onPressed: () {
        Navigator.pop(context, DialogDemoAction.cancel.toString());
      },
    ),
    FlatButton(
      child: Text(
        'OK',
        style: Theme.of(context).textTheme.button.copyWith(
            fontSize: 12.0, color: Theme.of(context).primaryColor),
      ),
      onPressed: () {
        Navigator.pop(context, DialogDemoAction.agree.toString());
      },
    )
  ],
);
}

List of params

Property Type Default Value Description
title Widget null The (optional) title of the dialog is displayed in a large font at the top of the dialog.
subTitle Widget null The (optional) subtitle of the dialog is displayed below title of the dialog.
content Widget null The (optional) content of the dialog is displayed in the center of the dialog in a lighter font.
actions List null The (optional) set of actions that are displayed at the bottom of the dialog.
children List null The (optional) content of the dialog is displayed in a [SingleChildScrollView] underneath the title.
headerColor Color null The (optional) header color is displayed in the header background.
backButtonColor Color Colors.white The (optional) back button color. By default its set to white.
closeButtonColor Color Colors.white The (optional) close button color. By default its set to white.
onBackButtonClicked VoidCallback null A callback function to get back button event from dialog. If back button is enabled this callback has to be provided in-order to get callbacks.
onCloseButtonClicked VoidCallback null A callback function to get close button event from dialog. If close button is enabled this callback has to be provided in-order to get callbacks.
enableBackButton bool false The (optional) value to enable/disable back button for a dialog.
enableCloseButton bool false The (optional) value to enable/disable close button for a dialog.
enableFullWidth bool true The (optional) value to stretch dialog to its max width.
enableFullHeight bool false The (optional) value to stretch dialog to its max height.
borderRadius double 10.0 The (optional) border radius of a dialog. by default its 10.0.

Thanks

If you liked my work, don’t forget to star the repo to show your support.

You might also like...

Aris fltrtuber - Flutter Web App to list top 30 YouTubers who create tutorial on Flutter

Aris fltrtuber - Flutter Web App to list top 30 YouTubers who create tutorial on Flutter

Fluttuber - Top 30 Flutter YouTubers Flutter Web App to list top 30 YouTubers wh

Jan 27, 2022

Prism is a beautiful open-source wallpapers app for Android. It is built with Dart on top of Google's Flutter Framework.

Prism is a beautiful open-source wallpapers app for Android. It is built with Dart on top of Google's Flutter Framework.

Prism Prism is a beautiful open-source wallpapers app for Android. It is built with Dart on top of Google's Flutter Framework. Prism brings you exclus

Dec 31, 2022

Flutter application for latest news by top newspapers . And allow for share articles with friends. Now available in night mode. Also landscape mode is available

Flutter application for latest news by top newspapers . And allow for share articles with friends. Now available in night mode. Also landscape mode is available

Breaking News Latest news for almost 55 country. Feature of saving article and search ariticles. Used API https://newsapi.org/ Note: if data is not ge

Oct 24, 2022

Flutter settings manager built on top of Shared Preferences

Settings Manager Flutter settings store built on top of shared preferences. Code Generator for supported types Usage import 'dart:async'; import 'pac

Dec 13, 2022

Flutter Tutorial - Scroll To Top In ListView

Flutter Tutorial - Scroll To Top In ListView

Flutter Tutorial - Scroll To Top In ListView Let's use Flutter to scroll to the top of a ListView and to detect the current ListView Scroll Position.

Apr 20, 2022

Basic todo mobile application built on top of the ETH blockchain with Flutter, Truffle and Ganache.

Basic todo mobile application built on top of the ETH blockchain with Flutter, Truffle and Ganache.

Todo-DAPP This project is a basic mobile Todo App build with Flutter. The backend consist in a Solidity contract running on the Ethereum Blockchain. C

Sep 28, 2022

Display a smart banner on top of the screen of your Flutter Web application.

Display a smart banner on top of the screen of your Flutter Web application.

Smart Banner Display a smart banner on top of the screen of your Flutter Web application. Inspired by smart-app-banner and react-smartbanner Try the o

Jul 10, 2023

(Top 10 GDG Devfest 2021) Mobile Application to prove intellectual property rights using blockchain technology and NFT

brainshield A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you started if t

Jan 12, 2022
Comments
  • Visually broken in web on latest flutter

    Visually broken in web on latest flutter

    Bildschirmfoto 2020-10-22 um 23 43 26

    • Buttons are too low and have a weird line above them
    • This only appears on web
    • These only appear when hovering

    This completely or partially goes away when adding a padding like this:

    Padding(
     // 8.0 = fully gone, normal behavior. 1.0 = line is half as thick. 0.0: See screenshot
      padding: const EdgeInsets.all(8.0),
      child: FlatButton(
        child: Text("Feedback"),
        onPressed: () {
          Get.back();
          AnalyticsHelper.showWiredash();
        },
      ),
    )
    

    I'm not really sure if this can be fixed by this library or if this is a flutter issue (I'm on beta!).

    I mainly wanted to share my workaround, maybe someone else has this issue as well..

    opened by ciriousjoker 0
Owner
Zubair Rehman
Android | Flutter Developer @ EmbraceIT
Zubair Rehman
Adaptive dialog - Show alert dialog or modal action sheet adaptively according to platform.

adaptive_dialog Show alert dialog or modal action sheet adaptively according to platform. showOkAlertDialog Convenient wrapper of showAlertDialog. iOS

Masayuki Ono (mono) 244 Dec 17, 2022
Animated dialog box - A pure dart package for showing animated alert box.

animated_dialog_box A pure dart package for showing animated alert box. Getting Started https://github.com/Shubham-Narkhede/animated_dialog_box/blob/m

Shubham-Narkhede 10 Jul 24, 2022
Binding and high-level wrapper on top of libssh - The SSH library!

Dart Binding to libssh version 0.9.6 binding and high-level wrapper on top of libssh - The SSH library! libssh is a multiplatform C library implementi

Isaque Neves 2 Dec 20, 2021
A wrapper on top of MFMailComposeViewController from iOS and Mail Intent on android

flutter_mailer Share email content via device Email Client - supports multiple Attachments Simple & quick plugin for cross application data sharing of

Tal Jacobson 43 May 22, 2022
Fast and productive web framework provided by Dart

See https://github.com/angulardart for current updates on this project. Packages Source code Published Version angular angular_forms angular_router an

Angular Dart Open Source Packages 1.9k Dec 15, 2022
A pure Dart utility library that checks for an internet connection by opening a socket to a list of specified addresses, each with individual port and timeout. Defaults are provided for convenience.

data_connection_checker A pure Dart utility library that checks for an internet connection by opening a socket to a list of specified addresses, each

Kristiyan Mitev 103 Nov 29, 2022
Flutter Dropdown Alert help to notify to user when success, warning or error like push notification

flutter_dropdown_alert A dropdown alert package for flutter Dropdown alert will help to notify to user when you call api success, error or something l

Tuan Van Le 12 Dec 17, 2022
Status Alert for Flutter

Status Alert for Flutter

Yako 125 Jan 8, 2023
This example uses a ScrollView, JSON Rest API, Navigation, Alert Pop Up, Progress Indicator, Globals, Images in a shared asset folder, and 100% Shared Code

This example uses a ScrollView, JSON Rest API, Navigation, Alert Pop Up, Progress Indicator, Globals, Images in a shared asset folder, and 100% Shared Code. Now with the ability to login with FaceID, TouchID, and Fingerprint Reader on Android.

Rody Davis 672 Jan 6, 2023
Flutter tableview - A flutter widget like iOS UITableview. let listView with section header and each section header will hover at the top.

中文 flutter_tableview A flutter widget like iOS UITableview. let listView with section header and each section header will hover at the top. Installing

null 41 Jul 22, 2022