@@ -29,10 +29,6 @@ enum DialogType {
29
29
class CustomDialog extends BaseDialog {
30
30
CustomDialog ({required SmartOverlayEntry overlayEntry}) : super (overlayEntry);
31
31
32
- DateTime ? clickMaskLastTime;
33
-
34
- var _timeRandom = Random ().nextInt (666666 ) + Random ().nextDouble ();
35
-
36
32
Future <T ?> show <T >({
37
33
required Widget widget,
38
34
required AlignmentGeometry alignment,
@@ -58,8 +54,10 @@ class CustomDialog extends BaseDialog {
58
54
required BuildContext ? bindWidget,
59
55
required Rect ? ignoreArea,
60
56
}) {
61
- if (! _handleMustOperate (
62
- tag: displayTime != null ? _getTimeKey (displayTime) : tag,
57
+ if (! _checkDebounce (debounce, DialogType .custom)) return Future .value (null );
58
+
59
+ final dialogInfo = _handleMustOperate (
60
+ tag: tag,
63
61
backDismiss: backDismiss,
64
62
keepSingle: keepSingle,
65
63
debounce: debounce,
@@ -68,7 +66,8 @@ class CustomDialog extends BaseDialog {
68
66
useSystem: useSystem,
69
67
bindPage: bindPage,
70
68
bindWidget: bindWidget,
71
- )) return Future .value (null );
69
+ displayTime: displayTime,
70
+ );
72
71
return mainDialog.show <T >(
73
72
widget: widget,
74
73
alignment: alignment,
@@ -80,7 +79,7 @@ class CustomDialog extends BaseDialog {
80
79
animationBuilder: animationBuilder,
81
80
maskColor: maskColor,
82
81
maskWidget: maskWidget,
83
- onDismiss: _handleDismiss (onDismiss, displayTime),
82
+ onDismiss: _handleDismiss (onDismiss, displayTime, dialogInfo ),
84
83
useSystem: useSystem,
85
84
reuse: true ,
86
85
awaitOverType: SmartDialog .config.custom.awaitOverType,
@@ -124,8 +123,10 @@ class CustomDialog extends BaseDialog {
124
123
required bool bindPage,
125
124
required BuildContext ? bindWidget,
126
125
}) {
127
- if (! _handleMustOperate (
128
- tag: displayTime != null ? _getTimeKey (displayTime) : tag,
126
+ if (! _checkDebounce (debounce, DialogType .attach)) return Future .value (null );
127
+
128
+ final dialogInfo = _handleMustOperate (
129
+ tag: tag,
129
130
backDismiss: backDismiss,
130
131
keepSingle: keepSingle,
131
132
debounce: debounce,
@@ -134,7 +135,8 @@ class CustomDialog extends BaseDialog {
134
135
useSystem: useSystem,
135
136
bindPage: bindPage,
136
137
bindWidget: bindWidget,
137
- )) return Future .value (null );
138
+ displayTime: displayTime,
139
+ );
138
140
return mainDialog.showAttach <T >(
139
141
targetContext: targetContext,
140
142
widget: widget,
@@ -152,7 +154,7 @@ class CustomDialog extends BaseDialog {
152
154
maskColor: maskColor,
153
155
maskWidget: maskWidget,
154
156
maskIgnoreArea: maskIgnoreArea,
155
- onDismiss: _handleDismiss (onDismiss, displayTime),
157
+ onDismiss: _handleDismiss (onDismiss, displayTime, dialogInfo ),
156
158
useSystem: useSystem,
157
159
awaitOverType: SmartDialog .config.attach.awaitOverType,
158
160
maskTriggerType: SmartDialog .config.attach.maskTriggerType,
@@ -164,10 +166,20 @@ class CustomDialog extends BaseDialog {
164
166
);
165
167
}
166
168
167
- VoidCallback _handleDismiss (VoidCallback ? onDismiss, Duration ? displayTime) {
169
+ VoidCallback _handleDismiss (
170
+ VoidCallback ? onDismiss,
171
+ Duration ? displayTime,
172
+ DialogInfo dialogInfo,
173
+ ) {
174
+ if (dialogInfo.tag == SmartTag .keepSingle) {
175
+ dialogInfo.displayTimer? .cancel ();
176
+ }
177
+
168
178
Timer ? timer;
169
- if (displayTime != null ) {
170
- timer = Timer (displayTime, () => dismiss (tag: _getTimeKey (displayTime)));
179
+ final tag = dialogInfo.tag;
180
+ if (displayTime != null && tag != null ) {
181
+ timer = Timer (displayTime, () => dismiss (tag: tag));
182
+ dialogInfo.displayTimer = timer;
171
183
}
172
184
173
185
return () {
@@ -176,9 +188,7 @@ class CustomDialog extends BaseDialog {
176
188
};
177
189
}
178
190
179
- String _getTimeKey (Duration time) => '${time .hashCode + _timeRandom }' ;
180
-
181
- bool _handleMustOperate ({
191
+ DialogInfo _handleMustOperate ({
182
192
required String ? tag,
183
193
required bool backDismiss,
184
194
required bool keepSingle,
@@ -188,45 +198,16 @@ class CustomDialog extends BaseDialog {
188
198
required bool useSystem,
189
199
required bool bindPage,
190
200
required BuildContext ? bindWidget,
201
+ required Duration ? displayTime,
191
202
}) {
192
- // debounce
193
- if (! _checkDebounce (debounce, type)) return false ;
194
-
195
- //handle dialog stack
196
- _handleDialogStack (
197
- tag: tag,
198
- backDismiss: backDismiss,
199
- keepSingle: keepSingle,
200
- type: type,
201
- permanent: permanent,
202
- useSystem: useSystem,
203
- bindPage: bindPage,
204
- bindWidget: bindWidget,
205
- );
206
-
207
203
SmartDialog .config.custom.isExist = DialogType .custom == type;
208
204
SmartDialog .config.attach.isExist = DialogType .attach == type;
209
- return true ;
210
- }
211
-
212
- void _handleDialogStack ({
213
- required String ? tag,
214
- required bool backDismiss,
215
- required bool keepSingle,
216
- required DialogType type,
217
- required bool permanent,
218
- required bool useSystem,
219
- required bool bindPage,
220
- required BuildContext ? bindWidget,
221
- }) {
222
- if (bindWidget != null ) {
223
- tag = tag ?? "${bindPage .hashCode }" ;
224
- }
225
205
206
+ DialogInfo dialogInfo;
226
207
if (keepSingle) {
227
- DialogInfo ? dialogInfo = _getDialog (tag: tag ?? SmartTag .keepSingle);
228
- if (dialogInfo == null ) {
229
- dialogInfo = DialogInfo (
208
+ var singleDialogInfo = _getDialog (tag: tag ?? SmartTag .keepSingle);
209
+ if (singleDialogInfo == null ) {
210
+ singleDialogInfo = DialogInfo (
230
211
dialog: this ,
231
212
backDismiss: backDismiss,
232
213
type: type,
@@ -237,26 +218,33 @@ class CustomDialog extends BaseDialog {
237
218
route: RouteRecord .curRoute,
238
219
bindWidget: bindWidget,
239
220
);
240
- _pushDialog (dialogInfo);
221
+ _pushDialog (singleDialogInfo);
222
+ }
223
+ mainDialog = singleDialogInfo.dialog.mainDialog;
224
+ dialogInfo = singleDialogInfo;
225
+ } else {
226
+ if (displayTime != null ) {
227
+ tag = tag ?? '${displayTime .hashCode + Random ().nextInt (666666 ) + Random ().nextDouble ()}' ;
228
+ } else if (bindWidget != null ) {
229
+ tag = tag ?? "${bindPage .hashCode }" ;
241
230
}
242
231
243
- mainDialog = dialogInfo.dialog.mainDialog;
244
- return ;
232
+ // handle dialog stack
233
+ dialogInfo = DialogInfo (
234
+ dialog: this ,
235
+ backDismiss: backDismiss,
236
+ type: type,
237
+ tag: tag,
238
+ permanent: permanent,
239
+ useSystem: useSystem,
240
+ bindPage: bindPage,
241
+ route: RouteRecord .curRoute,
242
+ bindWidget: bindWidget,
243
+ );
244
+ _pushDialog (dialogInfo);
245
245
}
246
246
247
- // handle dialog stack
248
- var dialogInfo = DialogInfo (
249
- dialog: this ,
250
- backDismiss: backDismiss,
251
- type: type,
252
- tag: tag,
253
- permanent: permanent,
254
- useSystem: useSystem,
255
- bindPage: bindPage,
256
- route: RouteRecord .curRoute,
257
- bindWidget: bindWidget,
258
- );
259
- _pushDialog (dialogInfo);
247
+ return dialogInfo;
260
248
}
261
249
262
250
void _pushDialog (DialogInfo dialogInfo) {
@@ -310,6 +298,8 @@ class CustomDialog extends BaseDialog {
310
298
return true ;
311
299
}
312
300
301
+ DateTime ? clickMaskLastTime;
302
+
313
303
bool _clickMaskDebounce () {
314
304
var now = DateTime .now ();
315
305
var isShake = clickMaskLastTime != null &&
0 commit comments