Skip to content

Commit 7a63315

Browse files
committed
fix #34 #41
1 parent 63ba55e commit 7a63315

File tree

7 files changed

+27
-11
lines changed

7 files changed

+27
-11
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
- 'showToast' add 'consumeEvent' param: [#27](https://github.com/fluttercandies/flutter_smart_dialog/issues/27)
44
- 'dismiss' can close dialogs with duplicate tags
55
- Fix [#28](https://github.com/fluttercandies/flutter_smart_dialog/issues/28)
6-
- Fix [#34](https://github.com/fluttercandies/flutter_smart_dialog/issues/34)
76
- Fix [#42](https://github.com/fluttercandies/flutter_smart_dialog/issues/42)
7+
- Fix [#34](https://github.com/fluttercandies/flutter_smart_dialog/issues/41) [#41](https://github.com/fluttercandies/flutter_smart_dialog/issues/34)
8+
- Add SmartStatus.allToast
89

910
# [3.3.x]
1011

lib/src/custom/custom_toast.dart

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ class CustomToast extends BaseDialog {
8484
handleMultiTypeToast(curType: type, fun: multiTypeToast);
8585
}
8686

87+
///--------------------------multi type toast--------------------------
88+
8789
Future<void> _normalToast({
8890
required Duration time,
8991
required Function() onShowToast,
@@ -114,7 +116,7 @@ class CustomToast extends BaseDialog {
114116
await _toastDelay(time);
115117
await _realDismiss();
116118

117-
_toastQueue.removeLast();
119+
if (_toastQueue.isNotEmpty) _toastQueue.removeLast();
118120
}
119121

120122
Future<void> _lastToast({
@@ -126,7 +128,7 @@ class CustomToast extends BaseDialog {
126128
await _toastDelay(time);
127129
if (_toastQueue.length == 1) await _realDismiss();
128130

129-
_toastQueue.removeLast();
131+
if (_toastQueue.isNotEmpty) _toastQueue.removeLast();
130132
}
131133

132134
Future<void> _firstAndLastToast({
@@ -148,10 +150,11 @@ class CustomToast extends BaseDialog {
148150
});
149151

150152
if (_toastQueue.length == 1) await _toastQueue.first();
151-
152153
if (_toastQueue.length > 2) _toastQueue.remove(_toastQueue.elementAt(1));
153154
}
154155

156+
///--------------------------multi type toast--------------------------
157+
155158
void handleMultiTypeToast({
156159
required SmartToastType curType,
157160
required Function() fun,
@@ -200,10 +203,12 @@ class CustomToast extends BaseDialog {
200203
config.isExistToast = false;
201204
}
202205

203-
Future<void> dismiss() async {
206+
Future<void> dismiss({bool closeAll = false}) async {
207+
if (closeAll) _toastQueue.clear();
204208
_curTime?.cancel();
205209
if (!(_curCompleter?.isCompleted ?? true)) _curCompleter?.complete();
206-
await Future.delayed(Duration(milliseconds: 1));
210+
await Future.delayed(SmartDialog.config.animationDuration);
211+
await Future.delayed(const Duration(milliseconds: 50));
207212
}
208213
}
209214

lib/src/helper/dialog_proxy.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,8 @@ class DialogProxy {
209209
if (loading) await _loading.dismiss(back: back);
210210
} else if (status == SmartStatus.toast) {
211211
await _toast.dismiss();
212+
} else if (status == SmartStatus.allToast) {
213+
await _toast.dismiss(closeAll: true);
212214
} else if (status == SmartStatus.loading) {
213215
await _loading.dismiss(back: back);
214216
} else if (status == SmartStatus.dialog) {

lib/src/smart_dialog.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ enum SmartStatus {
1717
/// 关闭toast(showToast)
1818
toast,
1919

20+
/// close all toasts(showToast)
21+
///
22+
/// 关闭所有toast(showToast)
23+
allToast,
24+
2025
/// close loading(showLoading)
2126
///
2227
/// 关闭loading(showLoading)

lib/src/widget/attach_dialog_widget.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,8 +295,9 @@ class _AttachDialogWidgetState extends State<AttachDialogWidget>
295295

296296
///等待动画结束,关闭动画资源
297297
Future<void> dismiss() async {
298+
if (_ctrlBg == null) return;
298299
//over animation
299-
_ctrlBg?.reverse();
300+
_ctrlBg!.reverse();
300301
_ctrlBody.reverse();
301302

302303
if (widget.isUseAnimation) {
@@ -307,6 +308,7 @@ class _AttachDialogWidgetState extends State<AttachDialogWidget>
307308
@override
308309
void dispose() {
309310
_ctrlBg?.dispose();
311+
_ctrlBg = null;
310312
_ctrlBody.dispose();
311313
super.dispose();
312314
}
@@ -321,7 +323,6 @@ class AttachDialogController extends BaseController {
321323

322324
@override
323325
Future<void> dismiss() async {
324-
await Future.delayed(Duration(milliseconds: 1));
325326
try {
326327
await _state?.dismiss();
327328
} catch (e) {

lib/src/widget/smart_dialog_widget.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,9 @@ class _SmartDialogWidgetState extends State<SmartDialogWidget>
178178

179179
///等待动画结束,关闭动画资源
180180
Future<void> dismiss() async {
181+
if (_ctrlBg == null) return;
181182
//结束动画
182-
_ctrlBg?.reverse();
183+
_ctrlBg!.reverse();
183184
_ctrlBody.reverse();
184185

185186
if (widget.isUseAnimation) {
@@ -190,7 +191,9 @@ class _SmartDialogWidgetState extends State<SmartDialogWidget>
190191
@override
191192
void dispose() {
192193
_ctrlBg?.dispose();
194+
_ctrlBg = null;
193195
_ctrlBody.dispose();
196+
194197
super.dispose();
195198
}
196199
}
@@ -204,7 +207,6 @@ class SmartDialogController extends BaseController {
204207

205208
@override
206209
Future<void> dismiss() async {
207-
await Future.delayed(Duration(milliseconds: 1));
208210
try {
209211
await _state?.dismiss();
210212
} catch (e) {

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.4.2+1
6+
version: 3.4.2+2
77
homepage: https://github.com/fluttercandies/flutter_smart_dialog
88
#flutter pub publish --server=https://pub.dartlang.org
99

0 commit comments

Comments
 (0)