Giter VIP home page Giter VIP logo

tipdialog's Introduction

TipDialog

  1. Please use 3.0.0 or above version, because earlier versions have serious performance issues
  2. if example no working, please google questions about Flutter upgrade AndroidX, AndroidX Migration - Flutterblock
  3. if run your app, it shows Error: Cannot run with sound null safety, please upgrade version to 4.0.0 Reference

中文版

A Flutter Tip Dialog

Loading Type Dialog Success Tye Dialog Fail Type Dialog
Loading Success Fail
Info Type Dialog Only Icon Dialog Onl Text Dialog
Info OnlyIcon OnlyText
Custom Icon Dialog Custom Body Dialog
CustomIcon CustomBody

1. Depend on it

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

dependencies:
  tip_dialog: ^4.0.0

2. Install it

You can install packages from the command line: with Flutter:

$ flutter packages get

3. Import it

Now in your Dart code, you can use:

import 'package:tip_dialog/tip_dialog.dart';

4. Use

Available attributes

/// [TipDialogContainer]
@required this.child,
/// automatically disappear time
this.duration: const Duration(seconds: 3),
/// mask layer alpha
this.maskAlpha: 0.3
// outside touchable, default false
// if true and onOutsideTouch not set, when use TipDialogHelper.loading(), you can touch mask layer to dismiss
// if true and onOutsideTouch set, when touching the mask layer, onOutsideTouch will be called.
this.outsideTouchable: false
// outside touch callback {@link OutsideTouchCallback}
this.onOutsideTouch

Global Use

/// Use [TipDialogContainer] globally
/// This widget can be globally supported
void main() => runApp(new MyApp());
class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      title: 'TipDialog Demo',
      theme: new ThemeData(),
      home: Stack(
        children: <Widget>[
          MyHomePage(title: 'TipDialog Demo Home Page'),
          // add [TipDialogContainer] widget here
          TipDialogContainer(duration: const Duration(seconds: 2))
        ],
      ),
    );
  }
}
/// use TipDialogHelper to show or dismiss tip
  Widget build(BuildContext context) {
    return new Scaffold(
        appBar: new AppBar(
          title: new Text(widget.title),
          elevation: 0.5,
        ),
        body: new ListView(children: <Widget>[
          _buildItem("Loading Type Tip Dialog", () async {
            TipDialogHelper.loading("Loading");
            await new Future.delayed(new Duration(seconds: 5));
            TipDialogHelper.dismiss();
          }),
          new Divider(),
          _buildItem("Success Type Tip Dialog", () async {
            TipDialogHelper.success("Loaded Successfully");
          }),
          new Divider(),
          _buildItem("Only text Tip Dialog", () async {
            TipDialogHelper.show(new TipDialog(
              type: TipDialogType.NOTHING,
              tip: "Do Not Repeat",
            ));
          }),
          new Divider(),
          _buildItem("Custom Icon Tip Dialog", () async {
            TipDialogHelper.show(new TipDialog.customIcon(
              icon: new Icon(
                Icons.file_download,
                color: Colors.white,
                size: 30.0,
                textDirection: TextDirection.ltr,
              ),
              tip: "Download",
            ));
          }),
          new Divider(),
          _buildItem("Custom Body Tip Dialog", () async {
            TipDialogHelper.show(new TipDialog.builder(
              bodyBuilder: (context) {
                return new Container(
                  width: 120.0,
                  height: 90.0,
                  alignment: Alignment.center,
                  child: new Text(
                    "Custom",
                    style: new TextStyle(color: Colors.white),
                    /// if TipDialogContainer are outside of MaterialApp,
                    /// here is a must to set
                    textDirection: TextDirection.ltr,
                  ),
                );
              },
              color: Colors.blue.withAlpha(150),
            ));
          }),
          new Divider(),
        ]));
  }

Use a custom widget when using [TipDialogContainer] globally, there may be appear some unexpected errors. such as Text or Icon, will appear similar to the following error.

No Directionality widget found.

Just set TextDirection just fine. See the custom Widget in the example for details.

5. Default Dialog Type

enum TipDialogType { NOTHING, LOADING, SUCCESS, FAIL, INFO }

NOTHING: no icon
LOADING: have a loading icon
SUCCESS: have a success icon
FAIL: have a fail icon
INFO: have a info icon
CUSTOM: custom tip dialog type, just a sign, do nothing

6. TipDialogHelper Method

/// tipDialog: Need to display the widget
///
/// isAutoDismiss: decide whether to disappear automatically, default is true
/// if true, the dialog will not automatically disappear
/// otherwise, the dialog will automatically disappear after the [Duration] set by [TipDialogContainer]
void show(Widget tipDialog, {bool isAutoDismiss: true});

/// dismiss dialog
void dismiss();

/// show info dialog
void info(String tip);
/// show fail dialog
void fail(String errMsg);
/// show success dialog
void success(String success);
/// show loading dialog
void loading(String loadingTip);

See the example directory for more details.

7. Change log

[4.0.0]

  • migrating to null safety

[3.1.0]

  • add outside touchable features

[3.0.0]

  • fix performance issues
  • easier way to call

[2.1.0]

  • add TipDialogHelper and deprecated TipDialogConnector

[2.0.1]

  • fix dismiss bug
  • upgrade android build gradle to 5.1.1

[2.0.0]

  • set default auto dismiss duration as 2 seconds
  • delete [TipDialogContainer] Partial parameters -- show -- outSideTouchable -- defaultTip -- defaultType
  • change show method parameter isLoading to isAutoDismiss
  • force display mask layer

[1.1.2] - (MODIFY)

  • fix infinite call dismiss bug
  • fixed an issue where setting the isLoading value is invalid

[1.1.1] - (MODIFY)

  • fix bugs that occur when using globally

[1.1.0] - (FUNCTION CHANGE)

  • add tip dialog global support

[1.0.1] - (MODIFY).

  • fix loading view version bug.
  • set default loading duration

[1.0.0] - first release.

  • add release.

tipdialog's People

Contributors

donny88 avatar inrush 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

Watchers

 avatar  avatar

tipdialog's Issues

[Request] Click to dismiss

Can I request to have click to dismiss functionality?
I want to set the dismiss duration to 5 second, but user can click the screen to dismiss the dialog.
Thanks.

Unhandled error setState() called after dispose(): TipDialogContainerState

Hi. i wish to ask. what if i have 2 window

Let's say window 1 has TipDialogContainer().
it clicks a button and opens window 2. I also place TipDialogContainer() here and if tip dialog shows up, it works ok.

i close window 2. then do operations in window 1, when tip dialog shows, it shows this error message


Unhandled Exception: Unhandled error setState() called after dispose(): TipDialogContainerState#45379(lifecycle state: defunct, not mounted, tickers: tracking 0 tickers)
E/flutter (23406): This error happens if you call setState() on a State object for a widget that no longer appears in the widget tree (e.g., whose parent widget no longer includes the widget in its build). This error can occur when code calls setState() from a timer or an animation callback.
E/flutter (23406): The preferred solution is to cancel the timer or stop listening to the animation in the dispose() callback. Another solution is to check the "mounted" property of this object before calling setState() to ensure the object is still in the tree.

The TipDialogHelper uses only 1 state and accesses it through its static variable. perhaps when the new window is closed, the state is killed off, there by when window 1 uses it, the static state has already been disposed which results in this error?

Any workarounds? thank you

How to show the TipDialog in the initState.

As title.
How can I show the TipDialog in the initState.
I want to show the TipDialog when the page is pushed, and dismiss the TipDialog when the data has been downloaded.

TipDialog 的显示和隐藏方法调用间隔太短,导致界面不可点击【可能】

1、在点击事件中,我先调用TipDIalog的显示方法,然后请求网络接口,接口回调内,隐藏TipDialog,然后我就一直点击这个按钮,结果在TipDialog隐藏后,界面就不响应任何触摸事件了。

2、后来我在网络请求方法之前,加入了一个延时操作,即调用TipDialog的显示方法后,延时500MS调用网络接口,然后一直点击按钮,这个现象就一直没有出现,一切正常。

个人猜测是网络请求过快,相当于TipDialog的Show方法刚调用完就调用了Dissmiss,会不是这样导致了这个问题,只有这样才能解释为什么我加了一个延时后就正常了。

TipDialog and loading_view doesn't support null safety

I installed the latest version as explained in the readme.

When i run my app, it shows

Error: Cannot run with sound null safety, because the following dependencies
don't support null safety:

  • package:tip_dialog
  • package:loading_view

any solution to this

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.