GithubHelp home page GithubHelp logo

ezaldeen99 / material_dialogs Goto Github PK

View Code? Open in Web Editor NEW
94.0 3.0 45.0 1.97 MB

A Flutter library aims to help you create animated, simple, and stylish Material Dialogs in your app.

License: Apache License 2.0

Dart 97.23% Kotlin 0.61% Swift 1.98% Objective-C 0.19%
flutter flutter-dialog flutterdev flutter-ui flutterpackage

material_dialogs's Introduction

pub

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(
          msg: 'Are you sure ? you can\'t undo this',
          title: "Delete",
          color: Colors.white,
          context: context,
          actions: [
            IconsOutlineButton(
              onPressed: () {},
              text: 'Cancel',
              iconData: Icons.cancel_outlined,
              textStyle: TextStyle(color: Colors.grey),
              iconColor: Colors.grey,
            ),
            IconsButton(
              onPressed: () {},
              text: 'Delete',
              iconData: Icons.delete,
              color: Colors.red,
              textStyle: TextStyle(color: Colors.white),
              iconColor: Colors.white,
            ),
          ])

IconsOutlineButton and IconsButton are both buttons widgets provided by the plugin to make things easier for you read more, you can use any other buttons if you want.

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(
          msg: 'Are you sure? you can\'t undo this action',
          title: 'Delete',
          context: context,
          actions: [
            IconsOutlineButton(
              onPressed: () {},
              text: 'Cancel',
              iconData: Icons.cancel_outlined,
              textStyle: TextStyle(color: Colors.grey),
              iconColor: Colors.grey,
            ),
            IconsButton(
              onPressed: () {},
              text: 'Delete',
              iconData: Icons.delete,
              color: Colors.red,
              textStyle: TextStyle(color: Colors.white),
              iconColor: Colors.white,
            ),
          ]),

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 lottieBuilder arg in Widget to set Animation to the dialog.

Dialogs.materialDialog(
          color: Colors.white,
          msg: 'Congratulations, you won 500 points',
          title: 'Congratulations',
          lottieBuilder: Lottie.asset(
          'assets/cong_example.json',
          fit: BoxFit.contain,
          ),
          context: context,
          actions: [
            IconsButton(
              onPressed: () {},
              text: 'Claim',
              iconData: Icons.done,
              color: Colors.blue,
              textStyle: TextStyle(color: Colors.white),
              iconColor: Colors.white,
            ),
          ]),

Icons buttons

The plugin provide you some out of the box customized buttons to help you creating your dialog.

IconsOutlineButton

This widget helps you create an outline button easily

    IconsOutlineButton(
      onPressed: () {},
      text: 'Cancel',
      iconData: Icons.cancel_outlined,
      textStyle: TextStyle(color: Colors.grey),
      iconColor: Colors.grey,
    ),

IconsButton

This widget helps you create a material button with icons in few lines of code

    IconsButton(
      onPressed: () {},
      text: 'Delete',
      iconData: Icons.delete,
      color: Colors.red,
      textStyle: TextStyle(color: Colors.white),
      iconColor: Colors.white,
    ),

CustomView

You can add your own Widget inside the dialog by using the customView attribute and CustomViewPosition to place it wherever you want.

Possible values
BEFORE_ANIMATION
BEFORE_TITLE (Default)
BEFORE_MESSAGE
BEFORE_ACTION
AFTER_ACTION
Dialogs.materialDialog(
          color: Colors.white,
          msg: 'Congratulations, you won 500 points',
          title: 'Congratulations',
          lottieBuilder: Lottie.asset(
          'assets/cong_example.json',
          fit: BoxFit.contain,
          ),
          customView: MySuperWidget(),
          customViewPosition: CustomViewPosition.BEFORE_ACTION,
          context: context,
          actions: [
            IconsButton(
              onPressed: () {},
              text: 'Claim',
              iconData: Icons.done,
              color: Colors.blue,
              textStyle: TextStyle(color: Colors.white),
              iconColor: Colors.white,
            ),
          ]),

Limitations

it's better to make your animation to 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 before using it in the plugin.

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.

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 :)

material_dialogs's People

Contributors

ezaldeen99 avatar istareternal avatar james-aidoo avatar jobijoba avatar saileshbro avatar sharpsan avatar vxern avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

material_dialogs's Issues

Closed Modal

how to close the modal? on my cancel button doesn't close the modal

`Navigator.pop(context);` doesn't work!

i tried the default CupertinoAlertDialog and was just working fine but when i switched to material_dialogs package then neither Navigator.pop(context) nor Navigator.of(context).pop did work, it pops into the previous page instead of vanishing the dialog!

edit1:
The relevant error-causing widget was: MaterialApp MaterialApp:file:///C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_no_internet_wi dget-0.0.9+17/lib/src/flutter_no_internet_widget.dart:71:12

Closing dialog programmatically

Hi,

Currently opening a materialDialog from a bottomMaterialDialog causes the bottomMaterialDialog to persist. Meaning that two taps are required to exit from both dialogs back to the main screen.

Seems like a method to close a dialog programmatically would help circumvent this problem.

Regression about customView

The customView parameter was working in version 1.0.0, but it's not working anymore in version 1.1.0.
The custom view is simply not showed.

Method call null on bottomMaterialDialog

Hi,

Dialogs.materialDialog() works, but Dialogs.bottomMaterialDialog() doesn't.
It produces this stacktrace:

The following NoSuchMethodError was thrown building BottomSheet(dirty, dependencies: [_InheritedTheme, _LocalizationsScope-[GlobalKey#e7ba0]], state: _BottomSheetState#a43c6):
The method '>' was called on null.
Receiver: null
Tried calling: >(0)

The relevant error-causing widget was
MaterialApp
lib\main.dart:12
When the exception was thrown, this was the stack
#0 Object.noSuchMethod (dart:core-patch/object_patch.dart:51:5)
#1 new FrameRate
package:lottie/src/frame_rate.dart:7
#2 Dialogs.bottomMaterialDialog.
package:material_dialogs/material_dialogs.dart:111
#3 _BottomSheetState.build
package:flutter/โ€ฆ/material/bottom_sheet.dart:266
#4 StatefulElement.build
package:flutter/โ€ฆ/widgets/framework.dart:4744
...

Any help would be appreciated :)

Greetings,

R.

Cannot pop when useRootNavigator

You discard the inner context of showDialog->DialogRoute.
So, when you set useRootNavigator=true, Strange things are going to happen.
Such as Navigator.of(context).pop() cannot pop dialog, but caused the overwritten page pop.

Feature request: customView position

It would be nice if the position of customView could be customizable.
Now the customView is always on the top of the title.
Sometimes it could be useful to have it in between of title and msg or below msg.

Can't update lottie to version 3

Because material_dialogs 1.1.4 depends on lottie ^2.1.0 and no versions of material_dialogs match >1.1.4 <2.0.0, material_dialogs ^1.1.4 requires lottie ^2.1.0.
So, because sarafi depends on both lottie ^3.1.0 and material_dialogs ^1.1.4, version solving failed.


You can try the following suggestion to make the pubspec resolve:
* Consider downgrading your constraint on lottie: flutter pub add lottie:^2.7.0

Stateful versions of dialogs

Hi,

Would it be possible to add stateful vesions of the dialogs?
Allowing to setState from one of the dialog buttons to for instance change the title or msg used for the dialog.

Greetings,

R.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.