bot_toast 3.0.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 97

BotToast 🤖 #

A really easy to use flutter toast library!

Build Status codecov

Language: English | 中文简体 #

🐲Overview #

  • In the true sense of Toast, you can call it whenever you need it, without any restrictions!

  • Feature-rich, support for displaying notifications, text, loading, attachments, etc. Toast

  • Support for popping up various custom Toasts, or you can pop up any Widget as long as it meets the requirements of the flutter code.

  • API is simple and easy to use

  • Pure flutter implementation

🐼Online Demo #

Online demo (Web effects may be biased, the actual effect is subject to the mobile phone)

🐳Example #

Sample project

🐺Renderings #

NotificationAttachedCustomAnimation
NotificationAttachedCustomAnimation
LoadingTextCustomWidget
LoadingTextCustomWidget

🐮Getting started #

1. add dependencies into you project pubspec.yaml file

dependencies:
     bot_toast: ^3.0.0

2. import BotToast lib

import 'package:bot_toast/bot_toast.dart';

3. initialization BotToast

MaterialApp(
      title: 'BotToast Demo',
      builder: BotToastInit(), //1. call BotToastInit
      navigatorObservers: [BotToastNavigatorObserver()], //2. registered route observer
      home: XxxxPage(),
  )

4. use BotToast

BotToast.showText(text:"xxxx");  //popup a text toast;
BotToast.showSimpleNotification(title: "init"); // popup a sample notification toast;
BotToast.showLoading(); //popup a sample loading toast
//popup a attachments toast
BotToast.showAttachedWidget(
    attachedWidget: (_) => Card(
          child: Padding(
            padding: const EdgeInsets.all(8.0),
            child: Icon(
              Icons.favorite,
              color: Colors.redAccent,
            ),
          ),
        ),
    duration: Duration(seconds: 2),
    target: Offset(520, 520));

🐼3.0 version #

Major changes:

  • Reimplemented the underlying initialization logic, the code is simpler and more general, and no longer depends on Navigator

  • Modify the initialization method

2.x version upgrade to 3.x version

change:

//2.x.x version initialization method
BotToastInit(
  child:MaterialApp(
      title: 'BotToast Demo',
      navigatorObservers: [BotToastNavigatorObserver()],
      home: XxxxPage(),
  )
);

to:

//3.x.x version initialization method
MaterialApp(
      title: 'BotToast Demo',
      builder: BotToastInit(), 
      navigatorObservers: [BotToastNavigatorObserver()],
      home: XxxxPage(),
  )

📃Documentation #

Documentation

[3.0.0] #

  • Reimplemented the underlying initialization logic, the code is simpler and more general, and no longer depends on Navigator

  • Modify the initialization method

[2.4.1] #

  • bug fix

[2.4.0] #

  • feat: Support to intercept click back button event

[2.3.1] #

[2.3.0] #

  • feat: add onClose callback

[2.2.1] #

  • bug fix: Use safeRun method to ensure normal running of rearrange

[2.2.0] #

  • 重构底层的实现方式以规避一些隐晦的bug

  • Refactor the underlying implementation to avoid some hidden bugs

[2.1.1] #

  • showSimpleNotification和showNotification方法添加onTap,onLongPress参数

  • showSimpleNotification and showNotification methods add onTap, onLongPress parameters

[2.1.0] #

  • bug fix: see #11

  • 移除BotToastInitkey参数

  • BotToast.init方法变为私有方法不再公开

  • 重构了初始化的方式

  • Remove the key parameter of BotToastInit

  • BotToast.init method becomes private and no longer public

  • Refactored the way to initialize

[2.0.0+2] #

  • Update document

[2.0.0+1] #

  • Delete useless print

[2.0.0] #

  • 修改初始化的方式,现在更为通用

  • 支持自定义Toast的动画和持续时间😉

  • showEnhancedWidget方法的closeFunc参数其含义已经发生了变化了,现在是等待closeFunc函数执行完毕才移除Toast

  • 添加showAnimationWidget方法,可以使用此方法来高度自定义一个有动画的Toast🤩

  • 移除reInit方法(2.0版本不再需要),以及PreferDirection.BelowPreferDirection.Upside这两个已经被废除的枚举

  • WrapWidget类型方法参数发生变化(破坏性的),但是如果你没有直接使用showEnhancedWidget方式的话,这个修改对1.x版本的代码其实是无影响的,如果有使用请看这里进行兼容1.x版本升级到2.x版本

  • showXxxNotification 添加dismissDirections参数:表示能进行滑动关闭的方向

  • showXxxText,showXxxLoading,showXxxNotification等方法添加了align参数:表示ToastContent区域在MainContent区域的对齐,可用于自定义Toast放置的位置

  • 修复了showAttachedWidget方法的一些bug

  • 支持flutter web(注意不能确保其稳定性)

  • 更新example的样式,并添加了更多demo


  • Modify the way of initialization, now more general

  • Support for custom Toast animation and animation duration😉

  • The meaning of the closeFunc parameter of the showEnhancedWidget method has changed. Now it is wait for the closeFunc function to complete before removing Toast.

  • Add the showAnimationWidget method, you can use this method to highly customize an animated Toast🤩

  • Remove the reInit method and the two deprecated enumerations PreferDirection.Below and PreferDirection.Upside

  • WrapWidget type method parameter changed (not compatible with 1.x version),see 1.x version upgrade 2.x version

  • showXxxNotification Add dismissDirections parameter

  • showXxxText, showXxxLoading, showXxxNotification method adds align parameter

  • Fixed some bugs in the showAttachedWidget method

  • Support flutter web (note that it cannot ensure its stability)

  • Updated the style of example and added more demos

[1.1.1] #

  • Bug fix:

The targetContext of the showAttachedWidget method causes a positioning error when it is inside the ScrollView.

showAttachedWidget方法的targetContext在ScrollView里面时导致定位出错

[1.1.0] #

  • 主要对showAttachedWidget方法进行了增强,现在支持更多方向,定位更准确了。

  • PreferDirection.BelowPreferDirection.Upside被废弃了,可以改用表达更清晰的topCenter,和bottomCenter来代替,且效果完全一致。这两个枚举将会在下个大版本被删除!

  • showAttachedWidgetpreferDirection 只是期望的方向,实际的位置可能因为空间不足而遭到调整

  • 实际调整顺序可以拿topLeft来进行说明,如果上方空间不足则调整为bottomLeft,然后左边空间不足的话就再判断右边的空间是否充足,充足的话结果为bottomRight,不充足最终结果为bottomCenter

  • 对于preferDirection=xxxCenter的情况,其交叉轴的偏移将会忽略

[1.0.3] #

  • 修复当pop所有Route再push Route会出现Bug
  • 加固了当项目使用MaterialApp.navigatorKey,能使用reInit重新初始化

[1.0.2] #

  • 放宽init重复初始化检查的程度
  • 替换scheduleFrame方法为ensureVisualUpdate

[1.0.1] #

  • Toast关闭后,清理向BotToastNavigatorObserver注册的函数

[1.0.0+2] #

  • 更新文档及在线例子

[1.0.0+1] #

  • 更新文档及在线例子

[1.0.0] #

  • 1.支持弹出Notification Toast
  • 2.支持某个Widget 显示
  • 3.对已有的功能进行重构,增强各个方法

[0.0.2] #

  • 添加Loading Toast

[0.0.1] #

  • 只是显示Widget到屏幕

example/lib/main.dart

import 'package:bot_toast/bot_toast.dart';
import 'package:flutter/material.dart';

import 'all.dart';
import 'attached_toast/attached_toast.dart';
import 'custom/custom_animation.dart';
import 'custom/custom_widget.dart';
import 'loading/custom_loading.dart';
import 'loading/loading.dart';
import 'notification/custom_notification.dart';
import 'notification/simple_notification.dart';
import 'notification/notification.dart' as notification;
import 'text/custom_text.dart';
import 'text/text.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      builder: BotToastInit(),
      title: 'BotToast Demo',
      navigatorObservers: [BotToastNavigatorObserver()],
      home: EnterPage(),
    );
  }
}

class EnterPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text("BotToast"),
          centerTitle: true,
        ),
        body: Align(
          alignment: Alignment.topCenter,
          child: SingleChildScrollView(
            child: Container(
              margin: EdgeInsets.only(top: 30),
              child: Column(children: <Widget>[
                Text(
                  "Notification",
                  style: TextStyle(fontWeight: FontWeight.w500, fontSize: 20),
                ),
                Divider(),
                Row(
                  children: <Widget>[
                    Expanded(
                      child: Container(
                        margin: EdgeInsets.symmetric(horizontal: 10),
                        child: RaisedButton(
                          onPressed: () {
                            Navigator.push(
                                context,
                                MaterialPageRoute(
                                    builder: (_) => SimpleNotification()));
                          },
                          child: Text("SimpleNotification"),
                        ),
                      ),
                    ),
                    Expanded(
                      child: Container(
                        margin: EdgeInsets.symmetric(horizontal: 10),
                        child: RaisedButton(
                          onPressed: () {
                            Navigator.push(
                                context,
                                MaterialPageRoute(
                                    builder: (_) =>
                                        notification.Notification()));
                          },
                          child: Text("Notification"),
                        ),
                      ),
                    )
                  ],
                ),
                Container(
                  width: double.infinity,
                  margin: EdgeInsets.symmetric(horizontal: 10),
                  child: RaisedButton(
                    onPressed: () {
                      Navigator.push(
                          context,
                          MaterialPageRoute(
                              builder: (_) => CustomNotification()));
                    },
                    child: Text("CustomNotification"),
                  ),
                ),
                Container(
                  height: 40,
                ),
                Text(
                  "TextToast",
                  style: TextStyle(fontWeight: FontWeight.w500, fontSize: 20),
                ),
                Divider(),
                Row(
                  children: <Widget>[
                    Expanded(
                      child: Container(
                        margin: EdgeInsets.symmetric(horizontal: 10),
                        child: RaisedButton(
                          onPressed: () {
                            Navigator.push(
                                context,
                                MaterialPageRoute(
                                    builder: (_) => TextSample()));
                          },
                          child: Text("TextToast"),
                        ),
                      ),
                    ),
                    Expanded(
                      child: Container(
                        margin: EdgeInsets.symmetric(horizontal: 10),
                        child: RaisedButton(
                          onPressed: () {
                            Navigator.push(
                                context,
                                MaterialPageRoute(
                                    builder: (_) => CustomText()));
                          },
                          child: Text("CustomText"),
                        ),
                      ),
                    )
                  ],
                ),
                Container(
                  height: 40,
                ),
                Text(
                  "Load",
                  style: TextStyle(fontWeight: FontWeight.w500, fontSize: 20),
                ),
                Divider(),
                Row(
                  children: <Widget>[
                    Expanded(
                      child: Container(
                        margin: EdgeInsets.symmetric(horizontal: 10),
                        child: RaisedButton(
                          onPressed: () {
                            Navigator.push(context,
                                MaterialPageRoute(builder: (_) => Loading()));
                          },
                          child: Text("Loading"),
                        ),
                      ),
                    ),
                    Expanded(
                      child: Container(
                        margin: EdgeInsets.symmetric(horizontal: 10),
                        child: RaisedButton(
                          onPressed: () {
                            Navigator.push(
                                context,
                                MaterialPageRoute(
                                    builder: (_) => CustomLoading()));
                          },
                          child: Text("CustomLoading"),
                        ),
                      ),
                    ),
                  ],
                ),
                Text(
                  'Other',
                  style: TextStyle(fontWeight: FontWeight.w500, fontSize: 20),
                ),
                const Divider(),
                Row(
                  children: <Widget>[
                    Expanded(
                      child: Container(
                        margin: EdgeInsets.symmetric(horizontal: 10),
                        child: RaisedButton(
                          onPressed: () {
                            Navigator.push(
                                context,
                                MaterialPageRoute(
                                    builder: (_) => AttachedToast()));
                          },
                          child: Text('AttachedToast'),
                        ),
                      ),
                    ),
                    Expanded(
                      child: Container(
                        margin: EdgeInsets.symmetric(horizontal: 10),
                        child: RaisedButton(
                          onPressed: () {
                            Navigator.push(context,
                                MaterialPageRoute(builder: (_) => All()));
                          },
                          child: Text("All"),
                        ),
                      ),
                    ),
                  ],
                ),
                Row(
                  children: <Widget>[
                    Expanded(
                      child: Container(
                        margin: EdgeInsets.symmetric(horizontal: 10),
                        child: RaisedButton(
                          onPressed: () {
                            Navigator.push(
                                context,
                                MaterialPageRoute(
                                    builder: (_) => CustomAnimation()));
                          },
                          child: const Text('CustomAnimation'),
                        ),
                      ),
                    ),
                    Expanded(
                      child: Container(
                        margin: EdgeInsets.symmetric(horizontal: 10),
                        child: RaisedButton(
                          onPressed: () {
                            Navigator.push(
                                context,
                                MaterialPageRoute(
                                    builder: (_) => CustomWidget()));
                          },
                          child: const Text('CustomWidget'),
                        ),
                      ),
                    )
                  ],
                )
              ]),
            ),
          ),
        ));
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  bot_toast: ^3.0.0

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

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

3. Import it

Now in your Dart code, you can use:


import 'package:bot_toast/bot_toast.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
95
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
97
Learn more about scoring.

We analyzed this package on May 24, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.1
  • pana: 0.13.8-dev
  • Flutter: 1.17.0

Health suggestions

Fix lib/src/bot_toast_init.dart. (-0.50 points)

Analysis of lib/src/bot_toast_init.dart reported 1 hint:

line 53 col 3: Avoid using unnecessary statements.

Fix lib/src/toast.dart. (-0.50 points)

Analysis of lib/src/toast.dart reported 1 hint:

line 784 col 20: 'body1' is deprecated and shouldn't be used. This is the term used in the 2014 version of material design. The modern term is bodyText2. This feature was deprecated after v1.13.8..

Fix lib/src/toast_navigator_observer.dart. (-0.50 points)

Analysis of lib/src/toast_navigator_observer.dart reported 1 hint:

line 53 col 29: The declaration '_' isn't referenced.

Fix additional 9 files with analysis or formatting issues.

Additional issues in the following files:

  • lib/bot_toast.dart (Run flutter format to format lib/bot_toast.dart.)
  • lib/src/basis.dart (Run flutter format to format lib/src/basis.dart.)
  • lib/src/bot_toast_manager.dart (Run flutter format to format lib/src/bot_toast_manager.dart.)
  • lib/src/key_board_safe_area.dart (Run flutter format to format lib/src/key_board_safe_area.dart.)
  • lib/src/toast_widget/animation.dart (Run flutter format to format lib/src/toast_widget/animation.dart.)
  • lib/src/toast_widget/loading.dart (Run flutter format to format lib/src/toast_widget/loading.dart.)
  • lib/src/toast_widget/notification.dart (Run flutter format to format lib/src/toast_widget/notification.dart.)
  • lib/src/toast_widget/text.dart (Run flutter format to format lib/src/toast_widget/text.dart.)
  • lib/src/toast_widget/toast_widget.dart (Run flutter format to format lib/src/toast_widget/toast_widget.dart.)

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.12
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test