@@ -29,10 +29,6 @@ enum DialogType {
2929class CustomDialog extends BaseDialog {
3030 CustomDialog ({required SmartOverlayEntry overlayEntry}) : super (overlayEntry);
3131
32- DateTime ? clickMaskLastTime;
33-
34- var _timeRandom = Random ().nextInt (666666 ) + Random ().nextDouble ();
35-
3632 Future <T ?> show <T >({
3733 required Widget widget,
3834 required AlignmentGeometry alignment,
@@ -58,8 +54,10 @@ class CustomDialog extends BaseDialog {
5854 required BuildContext ? bindWidget,
5955 required Rect ? ignoreArea,
6056 }) {
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,
6361 backDismiss: backDismiss,
6462 keepSingle: keepSingle,
6563 debounce: debounce,
@@ -68,7 +66,8 @@ class CustomDialog extends BaseDialog {
6866 useSystem: useSystem,
6967 bindPage: bindPage,
7068 bindWidget: bindWidget,
71- )) return Future .value (null );
69+ displayTime: displayTime,
70+ );
7271 return mainDialog.show <T >(
7372 widget: widget,
7473 alignment: alignment,
@@ -80,7 +79,7 @@ class CustomDialog extends BaseDialog {
8079 animationBuilder: animationBuilder,
8180 maskColor: maskColor,
8281 maskWidget: maskWidget,
83- onDismiss: _handleDismiss (onDismiss, displayTime),
82+ onDismiss: _handleDismiss (onDismiss, displayTime, dialogInfo ),
8483 useSystem: useSystem,
8584 reuse: true ,
8685 awaitOverType: SmartDialog .config.custom.awaitOverType,
@@ -124,8 +123,10 @@ class CustomDialog extends BaseDialog {
124123 required bool bindPage,
125124 required BuildContext ? bindWidget,
126125 }) {
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,
129130 backDismiss: backDismiss,
130131 keepSingle: keepSingle,
131132 debounce: debounce,
@@ -134,7 +135,8 @@ class CustomDialog extends BaseDialog {
134135 useSystem: useSystem,
135136 bindPage: bindPage,
136137 bindWidget: bindWidget,
137- )) return Future .value (null );
138+ displayTime: displayTime,
139+ );
138140 return mainDialog.showAttach <T >(
139141 targetContext: targetContext,
140142 widget: widget,
@@ -152,7 +154,7 @@ class CustomDialog extends BaseDialog {
152154 maskColor: maskColor,
153155 maskWidget: maskWidget,
154156 maskIgnoreArea: maskIgnoreArea,
155- onDismiss: _handleDismiss (onDismiss, displayTime),
157+ onDismiss: _handleDismiss (onDismiss, displayTime, dialogInfo ),
156158 useSystem: useSystem,
157159 awaitOverType: SmartDialog .config.attach.awaitOverType,
158160 maskTriggerType: SmartDialog .config.attach.maskTriggerType,
@@ -164,10 +166,20 @@ class CustomDialog extends BaseDialog {
164166 );
165167 }
166168
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+
168178 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;
171183 }
172184
173185 return () {
@@ -176,9 +188,7 @@ class CustomDialog extends BaseDialog {
176188 };
177189 }
178190
179- String _getTimeKey (Duration time) => '${time .hashCode + _timeRandom }' ;
180-
181- bool _handleMustOperate ({
191+ DialogInfo _handleMustOperate ({
182192 required String ? tag,
183193 required bool backDismiss,
184194 required bool keepSingle,
@@ -188,45 +198,16 @@ class CustomDialog extends BaseDialog {
188198 required bool useSystem,
189199 required bool bindPage,
190200 required BuildContext ? bindWidget,
201+ required Duration ? displayTime,
191202 }) {
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-
207203 SmartDialog .config.custom.isExist = DialogType .custom == type;
208204 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- }
225205
206+ DialogInfo dialogInfo;
226207 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 (
230211 dialog: this ,
231212 backDismiss: backDismiss,
232213 type: type,
@@ -237,26 +218,33 @@ class CustomDialog extends BaseDialog {
237218 route: RouteRecord .curRoute,
238219 bindWidget: bindWidget,
239220 );
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 }" ;
241230 }
242231
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);
245245 }
246246
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;
260248 }
261249
262250 void _pushDialog (DialogInfo dialogInfo) {
@@ -310,6 +298,8 @@ class CustomDialog extends BaseDialog {
310298 return true ;
311299 }
312300
301+ DateTime ? clickMaskLastTime;
302+
313303 bool _clickMaskDebounce () {
314304 var now = DateTime .now ();
315305 var isShake = clickMaskLastTime != null &&
0 commit comments