@@ -5,6 +5,7 @@ import 'package:flutter/material.dart';
55import 'package:flutter_smart_dialog/src/data/dialog_info.dart' ;
66import 'package:flutter_smart_dialog/src/data/smart_tag.dart' ;
77import 'package:flutter_smart_dialog/src/helper/dialog_proxy.dart' ;
8+ import 'package:flutter_smart_dialog/src/helper/monitor_widget_helper.dart' ;
89import 'package:flutter_smart_dialog/src/helper/route_record.dart' ;
910import 'package:flutter_smart_dialog/src/util/view_utils.dart' ;
1011import 'package:flutter_smart_dialog/src/widget/attach_dialog_widget.dart' ;
@@ -56,6 +57,7 @@ class CustomDialog extends BaseDialog {
5657 required bool permanent,
5758 required bool useSystem,
5859 required bool bindPage,
60+ required BuildContext ? bindWidget,
5961 }) {
6062 if (! _handleMustOperate (
6163 tag: displayTime != null ? _getTimeKey (displayTime) : tag,
@@ -66,6 +68,7 @@ class CustomDialog extends BaseDialog {
6668 permanent: permanent,
6769 useSystem: useSystem,
6870 bindPage: bindPage,
71+ bindWidget: bindWidget,
6972 )) return Future .value (null );
7073 return mainDialog.show <T >(
7174 widget: widget,
@@ -116,6 +119,7 @@ class CustomDialog extends BaseDialog {
116119 required bool permanent,
117120 required bool useSystem,
118121 required bool bindPage,
122+ required BuildContext ? bindWidget,
119123 }) {
120124 if (! _handleMustOperate (
121125 tag: displayTime != null ? _getTimeKey (displayTime) : tag,
@@ -126,6 +130,7 @@ class CustomDialog extends BaseDialog {
126130 permanent: permanent,
127131 useSystem: useSystem,
128132 bindPage: bindPage,
133+ bindWidget: bindWidget,
129134 )) return Future .value (null );
130135 return mainDialog.showAttach <T >(
131136 targetContext: targetContext,
@@ -177,6 +182,7 @@ class CustomDialog extends BaseDialog {
177182 required bool permanent,
178183 required bool useSystem,
179184 required bool bindPage,
185+ required BuildContext ? bindWidget,
180186 }) {
181187 // debounce
182188 if (! _checkDebounce (debounce, type)) return false ;
@@ -190,6 +196,7 @@ class CustomDialog extends BaseDialog {
190196 permanent: permanent,
191197 useSystem: useSystem,
192198 bindPage: bindPage,
199+ bindWidget: bindWidget,
193200 );
194201
195202 SmartDialog .config.custom.isExist = DialogType .custom == type;
@@ -205,7 +212,12 @@ class CustomDialog extends BaseDialog {
205212 required bool permanent,
206213 required bool useSystem,
207214 required bool bindPage,
215+ required BuildContext ? bindWidget,
208216 }) {
217+ if (bindWidget != null ) {
218+ tag = tag ?? "${bindPage .hashCode }" ;
219+ }
220+
209221 if (keepSingle) {
210222 DialogInfo ? dialogInfo = _getDialog (tag: SmartTag .keepSingle);
211223 if (dialogInfo == null ) {
@@ -218,6 +230,7 @@ class CustomDialog extends BaseDialog {
218230 useSystem: useSystem,
219231 bindPage: bindPage,
220232 route: RouteRecord .curRoute,
233+ bindWidget: bindWidget,
221234 );
222235 _pushDialog (dialogInfo);
223236 mainDialogSingle = mainDialog;
@@ -237,6 +250,7 @@ class CustomDialog extends BaseDialog {
237250 useSystem: useSystem,
238251 bindPage: bindPage,
239252 route: RouteRecord .curRoute,
253+ bindWidget: bindWidget,
240254 );
241255 _pushDialog (dialogInfo);
242256 }
@@ -248,6 +262,10 @@ class CustomDialog extends BaseDialog {
248262 } else {
249263 proxy.dialogQueue.addLast (dialogInfo);
250264 }
265+ if (dialogInfo.bindWidget != null ) {
266+ MonitorWidgetHelper .instance.monitorDialogQueue.add (dialogInfo);
267+ }
268+
251269 // insert the dialog carrier into the page
252270 ViewUtils .addSafeUse (() {
253271 Overlay .of (DialogProxy .contextOverlay)! .insert (
@@ -356,6 +374,9 @@ class CustomDialog extends BaseDialog {
356374 //handle close dialog
357375 var proxy = DialogProxy .instance;
358376 proxy.dialogQueue.remove (info);
377+ if (info.bindWidget != null ) {
378+ MonitorWidgetHelper .instance.monitorDialogQueue.remove (info);
379+ }
359380
360381 //check if the queue contains a custom dialog or attach dialog
361382 proxy.config.custom.isExist = false ;
@@ -410,8 +431,12 @@ class CustomDialog extends BaseDialog {
410431 //handle normal dialog
411432 for (var i = dialogQueue.length - 1 ; i >= 0 ; i-- ) {
412433 if (dialogQueue.isEmpty) break ;
413- if (type == DialogType .dialog || list[i].type == type) {
414- info = list[i];
434+ var item = list[i];
435+ if (! item.dialog.mainDialog.visible) {
436+ continue ;
437+ }
438+ if (type == DialogType .dialog || item.type == type) {
439+ info = item;
415440 break ;
416441 }
417442 }
0 commit comments