Skip to content

Commit

Permalink
Merge pull request #46 from MMMzq/dev
Browse files Browse the repository at this point in the history
2.4.0
  • Loading branch information
MMMzq authored Mar 28, 2020
2 parents 7c1e291 + 720bcfe commit 6136790
Show file tree
Hide file tree
Showing 24 changed files with 435 additions and 345 deletions.
11 changes: 10 additions & 1 deletion API.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ clickClose | 是否在点击屏幕触发事件时自动关闭该Toast
ignoreContentClick | 是否忽视ToastContext区域如果为true时,用户点击该ToastContext区域时,用户可以的点击事件可以正常到达到Page上,换一句话说就是透明的(即便是Toast背景颜色不是透明),如果为false,则情况反之
onlyOne | 表示是否该分组内是否在同一时间里只存在一个Toast,区分是哪一个组是按照[groupKey]来区分的
backgroundColor | MainContent区域的背景颜色
backButtonBehavior | 点击物理返回键的行为(在android上等同于物理的返回键),注意不是导航条上的返回按钮,如果为[BackButtonBehavior.ignore]则拦截返回事件,如果为[BackButtonBehavior.close]则关闭该toast,并且拦截事件停止冒泡,如果为null or [BackButtonBehavior.none]则不拦截事件

<br>

Expand All @@ -56,7 +57,7 @@ hideCloseButton | 否 | false| 是否隐藏关闭按钮
duration | 否 | ```Duration(seconds: 2)```| [duration说明](#通用参数说明)
crossPage | 否 | true| [crossPage说明](#通用参数说明)
onlyOne | 否 | true| [onlyOne说明](#通用参数说明)

backButtonBehavior | 否 | 无 | [backButtonBehavior说明](#通用参数说明)
<br>

#### 2.BotToast.showNotification
Expand All @@ -81,6 +82,7 @@ duration | 否 | ```Duration(seconds: 2)```| [duration说明](#通用参数说
crossPage | 否 | true| [crossPage说明](#通用参数说明)
onlyOne | 否 | true| [onlyOne说明](#通用参数说明)
enableSlideOff | 否 | true| 是否能滑动删除
backButtonBehavior | 否 | 无 | [backButtonBehavior说明](#通用参数说明)

<br>

Expand All @@ -100,6 +102,7 @@ enableSlideOff | 否 | true| 是否能滑动删除
duration | 否 | ```Duration(seconds: 2)```| [duration说明](#通用参数说明)
crossPage | 否 | true| [crossPage说明](#通用参数说明)
onlyOne | 否 | true| [onlyOne说明](#通用参数说明)
backButtonBehavior | 否 | 无 | [backButtonBehavior说明](#通用参数说明)

<br>

Expand Down Expand Up @@ -149,6 +152,7 @@ duration | 否 | ```Duration(seconds: 2)```| [duration说明](#通用参数说
onlyOne | 否 | true| [onlyOne说明](#通用参数说明)
crossPage | 否 | true| [crossPage说明](#通用参数说明)
clickClose | 否 | false| [clickClose说明](#通用参数说明)
backButtonBehavior | 否 | 无 | [backButtonBehavior说明](#通用参数说明)

<br>

Expand All @@ -169,6 +173,7 @@ onlyOne | 否 | false| [onlyOne说明](#通用参数说明)
clickClose | 否 | false| [clickClose说明](#通用参数说明)
ignoreContentClick | 否 | false| [ignoreContentClick说明](#通用参数说明)
backgroundColor | 否 | ```Colors.transparent```| [backgroundColor说明](#通用参数说明)
backButtonBehavior | 否 | 无 | [backButtonBehavior说明](#通用参数说明)

<br>

Expand All @@ -187,6 +192,7 @@ crossPage | 否 | true| [crossPage说明](#通用参数说明)
clickClose | 否 | false| [clickClose说明](#通用参数说明)
allowClick | 否 | false| [allowClick说明](#通用参数说明)
backgroundColor | 否 | ```Colors.black26```| [backgroundColor说明](#通用参数说明)
backButtonBehavior | 否 | 无 | [backButtonBehavior说明](#通用参数说明)

<br>

Expand All @@ -208,6 +214,7 @@ allowClick | 否 | false| [allowClick说明](#通用参数说明)
crossPage | 否 | false| [crossPage说明](#通用参数说明)
duration | 否 | 无| [duration说明](#通用参数说明)
backgroundColor | 否 | ```Colors.black26```| [backgroundColor说明](#通用参数说明)
backButtonBehavior | 否 | 无 | [backButtonBehavior说明](#通用参数说明)

<br>

Expand All @@ -232,6 +239,7 @@ closeFunc | 否 | 无 | [说明请看showEnhancedWidget.closeFunc](#10bottoastsh
warpWidget | 否 | 无 | [warpWidget说明](#10bottoastshowenhancedwidget)
duration | 否 | 无| [duration说明](#通用参数说明)
backgroundColor | 否 | ```Colors.transparent```| [backgroundColor说明](#通用参数说明)
backButtonBehavior | 否 | 无 | [backButtonBehavior说明](#通用参数说明)

<br>

Expand All @@ -252,6 +260,7 @@ closeFunc | 否 | 无 | 该函数参数主要目的使Toast关闭之做一些处
warpWidget | 否 | 无 | 一个wrap函数,可以用来warp MainContent区域,例如[showCustomLoading]就包裹了一个动画让MainContent区域也具有动画
duration | 否 | 无| [duration说明](#通用参数说明)
backgroundColor | 否 | ```Colors.transparent```| [backgroundColor说明](#通用参数说明)
backButtonBehavior | 否 | 无 | [backButtonBehavior说明](#通用参数说明)

<br>

Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## [2.4.0]
* feat: Support to intercept click back button event

## [2.3.1]
* fix: bug [#43](https://github.com/MMMzq/bot_toast/issues/43)

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ BotToast 🤖
=========
A really easy to use flutter toast library!

[![](https://img.shields.io/pub/v/bot_toast.svg?label=bot_toast&logo=https%3A%2F%2Fpub.flutter-io.cn%2Fpackages%2Fbot_toast)](https://pub.flutter-io.cn/packages/bot_toast)
[![](https://img.shields.io/pub/v/bot_toast.svg?label=bot_toast&logo=https%3A%2F%2Fpub.flutter-io.cn%2Fpackages%2Fbot_toast)](https://pub.dev/packages/bot_toast)
[![Build Status](https://github.com/MMMzq/bot_toast/workflows/CI/badge.svg)](https://github.com/MMMzq/bot_toast/actions)
[![codecov](https://codecov.io/gh/MMMzq/bot_toast/branch/master/graph/badge.svg)](https://codecov.io/gh/MMMzq/bot_toast)

Expand Down Expand Up @@ -51,7 +51,7 @@ Loading|Text|CustomWidget
#### 1. add dependencies into you project pubspec.yaml file
``` dart
dependencies:
bot_toast: ^2.3.1
bot_toast: ^2.4.0
```

#### 2. import BotToast lib
Expand Down
2 changes: 1 addition & 1 deletion README_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ Loading|Text|CustomWidget
#### 1. pubspec.yaml文件里添加依赖
``` dart
dependencies:
bot_toast: ^2.3.1
bot_toast: ^2.4.0
```

#### 2. 导入BotToast库
Expand Down
Binary file modified doc/gif/attached.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified doc/gif/custom_animation.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified doc/gif/custom_widget.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified doc/gif/loading.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified doc/gif/notification.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified doc/gif/text.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 0 additions & 29 deletions example/lib/attached_toast/attached_toast.dart
Original file line number Diff line number Diff line change
Expand Up @@ -490,14 +490,6 @@ class _AttachedToastState extends State<AttachedToast> {
},
),
),
Divider(),
Text("code"),
Divider(),
Text(
_code,
textAlign: TextAlign.start,
),
Divider(),
],
),
),
Expand All @@ -506,24 +498,3 @@ class _AttachedToastState extends State<AttachedToast> {
}
}

String _code = """
BotToast.showAttachedWidget(
target: target,
targetContext: context,
verticalOffset: verticalOffset,
duration: Duration(seconds: second),
preferDirection: preferDirection,
ignoreContentClick: ignoreContentClick,
onlyOne: onlyOne,
allowClick: allowClick,
backgroundColor: Color(backgroundColor),
attachedWidget: (cancel) => (Card(
child: IconButton(
padding: EdgeInsets.all(20),
onPressed: (){
BotToast.showSimpleNotification(title: "Let's go travel together.😘");
},
icon: Icon(Icons.favorite,color: Colors.redAccent,),
),
)));
""";
121 changes: 39 additions & 82 deletions example/lib/custom/custom_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,16 @@ import 'package:bot_toast/bot_toast.dart';
import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart';

void showAlertDialog(bool blockPopup,
void showAlertDialog(BackButtonBehavior backButtonBehavior,
{VoidCallback cancel,
VoidCallback confirm,
VoidCallback backgroundReturn,
VoidCallback physicalBackButton}) {
VoidCallback backgroundReturn}) {
BotToast.showAnimationWidget(
clickClose: false,
allowClick: false,
onlyOne: true,
crossPage: true,
wrapAnimation: (controller, cancel, child) => BackgroundRoute(
child: child,
blockPopup: blockPopup,
cancelFunc: cancel,
physicalButtonPopCallback: () {
physicalBackButton?.call();
},
),
backButtonBehavior: backButtonBehavior,
wrapToastAnimation: (controller, cancel, child) => Stack(
children: <Widget>[
GestureDetector(
Expand Down Expand Up @@ -81,7 +73,7 @@ class CustomWidget extends StatefulWidget {
}

class _CustomWidgetState extends State<CustomWidget> {
bool blockPopup = false;
BackButtonBehavior backButtonBehavior = BackButtonBehavior.none;

@override
Widget build(BuildContext context) {
Expand All @@ -97,26 +89,50 @@ class _CustomWidgetState extends State<CustomWidget> {
children: <Widget>[
RaisedButton(
onPressed: () {
showAlertDialog(blockPopup, cancel: () {
showAlertDialog(backButtonBehavior, cancel: () {
BotToast.showText(text: 'Click cancel');
}, confirm: () {
BotToast.showText(text: 'Click confirm');
}, backgroundReturn: () {
BotToast.showText(text: 'Click background');
}, physicalBackButton: () {
BotToast.showText(text: 'Click the physical back button');
});
},
child: const Text('customWidget'),
),
SwitchListTile(
value: blockPopup,
onChanged: (value) {
setState(() {
blockPopup = value;
});
},
title: const Text('DisablePhysicalButton: '),
Center(child: Text('BackButtonBehavior'),),
Row(
children: <Widget>[
Expanded(
child: RadioListTile(value: BackButtonBehavior.none,
groupValue: backButtonBehavior,
onChanged: (value) {
setState(() {
backButtonBehavior = value;
});
},
title: Text('none'),),
),
Expanded(
child: RadioListTile(value: BackButtonBehavior.ignore,
groupValue: backButtonBehavior,
onChanged: (value) {
setState(() {
backButtonBehavior = value;
});
},
title: Text('ignore'),),
),
Expanded(
child: RadioListTile(value: BackButtonBehavior.close,
groupValue: backButtonBehavior,
onChanged: (value) {
setState(() {
backButtonBehavior = value;
});
},
title: Text('close'),),
)
],
),
const Divider(),
],
Expand All @@ -127,23 +143,7 @@ class _CustomWidgetState extends State<CustomWidget> {
}
}

class BackgroundRoute extends StatefulWidget {
final Widget child;
final bool blockPopup;
final CancelFunc cancelFunc;
final VoidCallback physicalButtonPopCallback;

const BackgroundRoute(
{Key key,
this.child,
this.blockPopup,
this.cancelFunc,
this.physicalButtonPopCallback})
: super(key: key);

@override
_BackgroundRouteState createState() => _BackgroundRouteState();
}

class CustomOffsetAnimation extends StatefulWidget {
final AnimationController controller;
Expand Down Expand Up @@ -196,46 +196,3 @@ class _CustomOffsetAnimationState extends State<CustomOffsetAnimation> {
}
}

class _BackgroundRouteState extends State<BackgroundRoute> {
bool _needPop = false;
NavigatorState _navigatorState;

@override
void initState() {
SchedulerBinding.instance.addPostFrameCallback((_) {
_navigatorState = Navigator.of(context);
_navigatorState.push(PageRouteBuilder(
opaque: false,
pageBuilder: (_, __, ___) => IgnorePointer(
child: WillPopScope(
child: Align(),
onWillPop: () async {
if (_needPop) {
return true;
}
if (!widget.blockPopup) {
widget.physicalButtonPopCallback?.call();
widget.cancelFunc();
}
return false;
},
),
)));
});
super.initState();
}

@override
void dispose() {
super.dispose();
_needPop = true;
SchedulerBinding.instance.addPostFrameCallback((_) {
_navigatorState.pop();
});
}

@override
Widget build(BuildContext context) {
return widget.child;
}
}
Loading

0 comments on commit 6136790

Please sign in to comment.