material_dialogs 0.0.2
material_dialogs: ^0.0.2 copied to clipboard
A Flutter package aims to help you create animated, simple, stylish Material Dialogs in your app.
Flutter Material Dialogs #
Flutter Material Dialogs 📱 #
A Flutter library aims to help you create 💪🏻animated, 😃 simple, 😎 stylish Material Dialogs in your app.
1. Material Dialog | 2. Animations Material Dialog | 3. Bottom Material Dialog | 4. Animations Bottom Dialog |
---|---|---|---|
![]() |
![]() |
![]() |
![]() |
Table of Contents: #
Introduction #
MaterialDialog This Plugin will be useful to create simple, animated, and beautiful dialogs in your next Flutter app. This library implements Airbnb's Lottie library to render After Effects animation in app.
Types of Dialog #
MaterialDialog library provides two types of dialog i.e.
1. Material Dialog | 2. Bottom Sheet Material Dialog |
---|---|
A normal material dialog which can have one or two buttons. | A Bottom Sheet material dialog which can have one or two buttons, is showed from bottom of device. |
![]() |
![]() |
Implementation #
Implementation of Material Dialog library is so easy. You can check /example directory for demo. Let's have look talk in details about it.
install #
i. pubspec
In pubspec.yaml
dependencies:
material_dialogs: _latest_version
Now in your Dart code, you can use:
import 'package:material_dialogs/material_dialogs.dart';
Details see pub.dev.
Create Dialog #
As there are two types of dialogs in library. Material Dialogs are instantiated as follows.
i. Material Dialog
Dialogs
class will be used to create your dialog, below is an example to show your dialog in the app.
Dialogs.materialDialog(
btn1Press: () {},
btn1Text: "Delete",
msg: 'Are you sure? you can\'t undo this',
title: "Delete",
btn2Text: "Cancel",
btn2Press: () {
Navigator.pop(context);
},
color: Colors.white,
btn1Icon: Icons.delete,
btn2Icon: Icons.cancel,
context: context,
)

ii. Bottom Sheet Material Dialog
Dialogs
class will be used to create your dialog, use bottomMaterialDialog
. Below is an example to show your dialog in the app.
Dialogs.bottomMaterialDialog(
btn1Press: () {},
btn1Text: 'Delete',
msg: 'Are you sure? you can\'t undo this',
title: 'Delete',
btn2Text: 'Cancel',
btn2Press: () {
Navigator.pop(context);
},
btn1Icon: Icons.delete,
btn2Icon: Icons.cancel,
context: context,
)

iii. Single Botton Dialogs
If you want a single button dialogs, simply add singleBtn: true
and please keep the btn2Press
and igonre its callback.
Dialogs.materialDialog(
btn1Press: () {},
btn1Text: 'Claim',
btn1Bcg: Colors.blue,
color: Colors.white,
msg: 'Congratulations, you won 500 points',
title: 'Congratulations',
singleBtn: true,
btn1Icon: Icons.done,
btn2Press: () {},
animations: 'assets/cong_example.json',
context: context,
),

Show Animations #
Animations in this library are implemented using Lottie animation library. You can get free animations files here.
*.json
file downloaded from LottieFiles should be placed in flutter project.
For example, here cong_example.json
animation file is used in the assets
folder to show congratulations animation in the example app.
In code, set animations: 'path to your animation file'
arg in Widget to set Animation to the dialog.
Lottie file should be passed to method. e.g. cong_example.json
.
Dialogs.materialDialog(
btn1Press: () {},
btn1Text: 'Claim',
btn1Bcg: Colors.blue,
color: Colors.white,
msg: 'Congratulations, you won 500 points',
title: 'Congratulations',
btn2Text: 'Cancel',
btn2IconColor: Colors.grey,
btn1Icon: Icons.done,
btn2Icon: Icons.cancel,
btn2Press: () {
Navigator.pop(context);
},
animations: 'assets/cong_example.json',
context: context,
)
Dialog State Listeners #
There are two callback events for Dialog.
Following are interfaces for implementations:
btn1Press
- Listens for dialog first button click event.btn2Press
- Listens for dialog second button click event.
for example
btn2Press: () {
Navigator.pop(context);
},
Limitations #
it's better to make you animation have the same background color as your dialog's background color, please use lottie editor to remove the background layer of your animation or make it same as your dialog background color.
Contribute #
Let's develop with collaborations. We would love to have contributions by raising issues and opening PRs. Filing an issue before PR is must.
Credits #
This library is built using following open-source libraries.
- Lottie for Flutter
- MaterialDialog-Android for inspiration
License #
Project is published under the Apache 2.0 license. Feel free to clone and modify repo as you want, but don't forget to add reference to authors :)