Skip to content

Commit e0523f5

Browse files
committed
toast add consumeEvent param;dismiss can close dialogs with duplicate tags
1 parent f3797c0 commit e0523f5

File tree

6 files changed

+30
-7
lines changed

6 files changed

+30
-7
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# [3.4.x]
2+
3+
- 'showToast' add 'consumeEvent' param
4+
- 'dismiss' can close dialogs with duplicate tags
5+
16
# [3.3.x]
27

38
- Notice: 'antiShake' renamed 'debounce'

lib/src/custom/custom_dialog.dart

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -280,17 +280,19 @@ class CustomDialog extends BaseDialog {
280280
DialogInfo? info;
281281
var dialogQueue = proxy.dialogQueue;
282282
var list = dialogQueue.toList();
283+
283284
for (var i = dialogQueue.length - 1; i >= 0; i--) {
284285
if (dialogQueue.isEmpty) break;
285286
var item = list[i];
286-
if (type == DialogType.dialog || item.type == type) {
287+
if (tag != null && item.tag == tag) {
288+
info = item;
289+
break;
290+
}else if (type == DialogType.dialog || item.type == type) {
287291
info = item;
288292
break;
289293
}
290294
}
291295

292-
DialogInfo? infoMap = tag != null ? proxy.dialogMap[tag] : null;
293-
info = tag != null ? infoMap : info;
294296
//handle prohibiting back event
295297
if (info != null && (!info.backDismiss && back)) return null;
296298

lib/src/helper/dialog_proxy.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ class DialogProxy {
179179
required Duration animationDuration,
180180
required Color maskColor,
181181
required Widget? maskWidget,
182+
required bool consumeEvent,
182183
required Duration time,
183184
required bool debounce,
184185
required SmartToastType type,
@@ -195,7 +196,7 @@ class DialogProxy {
195196
time: time,
196197
debounce: debounce,
197198
type: type,
198-
widget: ToastHelper(child: widget),
199+
widget: ToastHelper(consumeEvent: consumeEvent, child: widget),
199200
);
200201
}
201202

lib/src/smart_dialog.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,9 @@ class SmartDialog {
447447
///
448448
/// [alignment]:control the location of toast on the screen
449449
///
450+
/// [consumeEvent]: default (false), true (toast will consume touch events),
451+
/// false (toast no longer consumes events, touch events can penetrate toast)
452+
///
450453
/// [time]:toast display time on the screen(Use the 'widget' param, this param will be invalid)
451454
///
452455
/// [debounceTemp]:debounce feature
@@ -478,6 +481,8 @@ class SmartDialog {
478481
///
479482
/// [alignment]:控制toast在屏幕上的显示位置(使用 'widget' 参数,该参数将失效)
480483
///
484+
/// [consumeEvent]:默认(false),true(toast会消耗触摸事件),false(toast不再消耗事件,触摸事件能穿透toast)
485+
///
481486
/// [time]:toast在屏幕上的显示时间
482487
///
483488
/// [debounceTemp]:防抖功能(debounce)
@@ -495,6 +500,7 @@ class SmartDialog {
495500
Color? maskColorTemp,
496501
Widget? maskWidgetTemp,
497502
AlignmentGeometry alignment = Alignment.bottomCenter,
503+
bool? consumeEvent,
498504
Duration? time,
499505
bool? debounceTemp,
500506
SmartToastType? type,
@@ -508,6 +514,7 @@ class SmartDialog {
508514
animationDuration: animationDurationTemp ?? Duration(milliseconds: 200),
509515
maskColor: maskColorTemp ?? config.maskColor,
510516
maskWidget: maskWidgetTemp ?? config.maskWidget,
517+
consumeEvent: consumeEvent ?? false,
511518
time: time ?? Duration(milliseconds: 2000),
512519
debounce: debounceTemp ?? config.debounce,
513520
type: type ?? SmartToastType.normal,

lib/src/widget/toast_helper.dart

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
import 'package:flutter/material.dart';
22

33
class ToastHelper extends StatefulWidget {
4-
ToastHelper({Key? key, required this.child}) : super(key: key);
4+
ToastHelper({
5+
Key? key,
6+
required this.consumeEvent,
7+
required this.child,
8+
}) : super(key: key);
9+
10+
final bool consumeEvent;
511

612
final Widget child;
713

@@ -24,7 +30,9 @@ class _ToastHelperState extends State<ToastHelper> with WidgetsBindingObserver {
2430
Widget build(BuildContext context) {
2531
return Container(
2632
margin: EdgeInsets.only(bottom: _keyboardHeight),
27-
child: IgnorePointer(child: widget.child),
33+
child: widget.consumeEvent
34+
? widget.child
35+
: IgnorePointer(child: widget.child),
2836
);
2937
}
3038

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ description:
33
An elegant Flutter Dialog solution,
44
Easily implement Toast, Loading and custom Dialog,
55
Make the use of the dialog easier!
6-
version: 3.3.9
6+
version: 3.4.0
77
homepage: https://github.com/fluttercandies/flutter_smart_dialog
88

99
environment:

0 commit comments

Comments
 (0)