Skip to content

Commit 716db55

Browse files
committed
revert the initialization implementation
1 parent 26c7f33 commit 716db55

File tree

9 files changed

+54
-265
lines changed

9 files changed

+54
-265
lines changed

lib/src/custom/custom_dialog.dart

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import 'package:flutter_smart_dialog/src/widget/attach_dialog_widget.dart';
1313
import '../config/enum_config.dart';
1414
import '../data/animation_param.dart';
1515
import '../data/base_dialog.dart';
16+
import '../data/notify_info.dart';
1617
import '../kit/debounce_utils.dart';
1718
import '../smart_dialog.dart';
1819
import '../widget/helper/smart_overlay_entry.dart';
@@ -262,11 +263,18 @@ class CustomDialog extends BaseDialog {
262263

263264
// insert the dialog carrier into the page
264265
ViewUtils.addSafeUse(() {
266+
NotifyInfo? firstNotify =
267+
proxy.notifyQueue.isNotEmpty ? proxy.notifyQueue.first : null;
265268
BuildContext overlayContext = dialogInfo.type == DialogType.custom
266-
? DialogProxy.timelyContextCustom
267-
: DialogProxy.timelyContextAttach;
269+
? DialogProxy.contextCustom
270+
: DialogProxy.contextAttach;
268271
try {
269-
overlay(overlayContext).insert(overlayEntry, below: proxy.entryNotify);
272+
overlay(overlayContext).insert(
273+
overlayEntry,
274+
below: firstNotify != null
275+
? firstNotify.dialog.overlayEntry
276+
: proxy.entryLoading,
277+
);
270278
} catch (e) {
271279
overlay(overlayContext).insert(overlayEntry);
272280
}

lib/src/custom/custom_notify.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,12 @@ class CustomNotify extends BaseDialog {
140140
// insert the dialog carrier into the page
141141
ViewUtils.addSafeUse(() {
142142
try {
143-
overlay(DialogProxy.timelyContextNotify).insert(
143+
overlay(DialogProxy.contextNotify).insert(
144144
overlayEntry,
145145
below: proxy.entryLoading,
146146
);
147147
} catch (e) {
148-
overlay(DialogProxy.timelyContextNotify).insert(overlayEntry);
148+
overlay(DialogProxy.contextNotify).insert(overlayEntry);
149149
}
150150
});
151151
}

lib/src/custom/main_dialog.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,6 @@ class MainDialog {
226226
Navigator.pop(DialogProxy.contextNavigator!);
227227
}
228228

229-
await DialogProxy.instance.smartOverlayController.dismiss();
230-
231229
// safety await
232230
await ViewUtils.awaitPostFrame();
233231

lib/src/custom/toast/custom_toast.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class CustomToast extends BaseDialog {
4444
showToast() {
4545
SmartDialog.config.toast.isExist = true;
4646
overlayEntry.remove();
47-
overlay(DialogProxy.timelyContextToast).insert(overlayEntry);
47+
overlay(DialogProxy.contextToast).insert(overlayEntry);
4848

4949
mainDialog.show(
5050
widget: widget,

lib/src/helper/dialog_proxy.dart

Lines changed: 7 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@ import '../config/smart_config.dart';
1616
import '../data/animation_param.dart';
1717
import '../data/notify_info.dart';
1818
import '../init_dialog.dart';
19-
import '../widget/helper/smart_overlay.dart';
2019
import '../widget/helper/smart_overlay_entry.dart';
21-
import 'show_helper.dart';
2220

2321
enum CloseType {
2422
// back event
@@ -48,7 +46,6 @@ enum DialogType {
4846
class DialogProxy {
4947
late SmartConfig config;
5048
late SmartOverlayEntry entryLoading;
51-
late SmartOverlayEntry entryNotify;
5249
late Queue<DialogInfo> dialogQueue;
5350
late Queue<NotifyInfo> notifyQueue;
5451
late CustomLoading loadingWidget;
@@ -62,14 +59,6 @@ class DialogProxy {
6259
static late BuildContext contextNotify;
6360
static late BuildContext contextToast;
6461

65-
static BuildContext get timelyContextCustom => contextCustom;
66-
67-
static BuildContext get timelyContextAttach => contextAttach;
68-
69-
static BuildContext get timelyContextNotify => contextNotify;
70-
71-
static BuildContext get timelyContextToast => contextToast;
72-
7362
static BuildContext? contextNavigator;
7463

7564
///set default loading widget
@@ -81,14 +70,10 @@ class DialogProxy {
8170
///set default toast widget
8271
late FlutterSmartNotifyStyle notifyStyle;
8372

84-
var smartOverlayController = SmartOverlayController();
85-
late ShowHelper showHelper;
86-
8773
DialogProxy._internal() {
8874
config = SmartConfig();
8975
dialogQueue = ListQueue();
9076
notifyQueue = ListQueue();
91-
showHelper = ShowHelper(smartOverlayController);
9277
}
9378

9479
void initialize(Set<SmartInitType> initType) {
@@ -98,10 +83,6 @@ class DialogProxy {
9883
});
9984
loadingWidget = CustomLoading(overlayEntry: entryLoading);
10085
}
101-
102-
if (initType.contains(SmartInitType.notify)) {
103-
entryNotify = SmartOverlayEntry(builder: (_) => const SizedBox.shrink());
104-
}
10586
}
10687

10788
Future<T?> show<T>({
@@ -128,8 +109,7 @@ class DialogProxy {
128109
required bool bindPage,
129110
required BuildContext? bindWidget,
130111
required Rect? ignoreArea,
131-
}) async {
132-
await showHelper.beforeShow();
112+
}) {
133113
CustomDialog? dialog;
134114
var entry = SmartOverlayEntry(
135115
builder: (BuildContext context) => dialog!.getWidget(),
@@ -181,8 +161,7 @@ class DialogProxy {
181161
required String? tag,
182162
required bool keepSingle,
183163
required SmartBackType backType,
184-
}) async {
185-
await showHelper.beforeShow();
164+
}) {
186165
CustomNotify? dialog;
187166
var entry = SmartOverlayEntry(
188167
builder: (BuildContext context) => dialog!.getWidget(),
@@ -239,8 +218,7 @@ class DialogProxy {
239218
required bool useSystem,
240219
required bool bindPage,
241220
required BuildContext? bindWidget,
242-
}) async {
243-
await showHelper.beforeShow();
221+
}) {
244222
CustomDialog? dialog;
245223
var entry = SmartOverlayEntry(
246224
builder: (BuildContext context) => dialog!.getWidget(),
@@ -294,8 +272,7 @@ class DialogProxy {
294272
required Duration? displayTime,
295273
required bool backDismiss,
296274
required Widget widget,
297-
}) async {
298-
await showHelper.beforeShow();
275+
}) {
299276
return loadingWidget.showLoading<T>(
300277
alignment: alignment,
301278
clickMaskDismiss: clickMaskDismiss,
@@ -333,8 +310,7 @@ class DialogProxy {
333310
required bool debounce,
334311
required SmartToastType displayType,
335312
required Widget widget,
336-
}) async {
337-
await showHelper.beforeShow();
313+
}) {
338314
CustomToast? toast;
339315
var entry = SmartOverlayEntry(
340316
builder: (BuildContext context) => toast!.getWidget(),
@@ -366,8 +342,7 @@ class DialogProxy {
366342
T? result,
367343
bool force = false,
368344
CloseType closeType = CloseType.normal,
369-
}) async {
370-
await showHelper.awaitShow();
345+
}) {
371346
if (status == SmartStatus.smart) {
372347
var loading = config.loading.isExist;
373348

@@ -423,7 +398,7 @@ class DialogProxy {
423398
}
424399

425400
DialogType? type = _convertEnum(status);
426-
if (type == null) return;
401+
if (type == null) return null;
427402
return CustomDialog.dismiss<T>(
428403
type: type,
429404
tag: tag,

lib/src/helper/show_helper.dart

Lines changed: 0 additions & 47 deletions
This file was deleted.

lib/src/init_dialog.dart

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import 'package:flutter_smart_dialog/src/kit/view_utils.dart';
55
import 'package:flutter_smart_dialog/src/widget/default/notify_alter.dart';
66
import 'package:flutter_smart_dialog/src/widget/default/notify_error.dart';
77
import 'package:flutter_smart_dialog/src/widget/default/notify_failure.dart';
8-
import 'package:flutter_smart_dialog/src/widget/helper/smart_overlay.dart';
98

109
import 'helper/dialog_proxy.dart';
1110
import 'helper/pop_monitor/boost_route_monitor.dart';
@@ -161,16 +160,39 @@ class _FlutterSmartDialogState extends State<FlutterSmartDialog> {
161160

162161
@override
163162
Widget build(BuildContext context) {
164-
return styleBuilder(Stack(children: [
165-
// main widget
166-
widget.child ?? const SizedBox.shrink(),
167-
168-
// dialog
169-
SmartOverlay(
170-
initType: initType,
171-
controller: DialogProxy.instance.smartOverlayController,
172-
)
173-
]));
163+
return styleBuilder(
164+
Overlay(initialEntries: [
165+
//main layout
166+
OverlayEntry(
167+
builder: (BuildContext context) {
168+
if (initType.contains(SmartInitType.custom)) {
169+
DialogProxy.contextCustom = context;
170+
}
171+
172+
if (initType.contains(SmartInitType.attach)) {
173+
DialogProxy.contextAttach = context;
174+
}
175+
176+
if (initType.contains(SmartInitType.notify)) {
177+
DialogProxy.contextNotify = context;
178+
}
179+
180+
if (initType.contains(SmartInitType.toast)) {
181+
DialogProxy.contextToast = context;
182+
}
183+
184+
return widget.child ?? Container();
185+
},
186+
),
187+
188+
// if (initType.contains(SmartInitType.notify))
189+
// DialogProxy.instance.entryNotify,
190+
191+
//provided separately for loading
192+
if (initType.contains(SmartInitType.loading))
193+
DialogProxy.instance.entryLoading,
194+
]),
195+
);
174196
}
175197

176198
BuildContext? getNavigatorContext(Navigator navigator) {

0 commit comments

Comments
 (0)