Skip to content

Commit

Permalink
revert the initialization implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
xdd666t committed Sep 16, 2024
1 parent 26c7f33 commit 716db55
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 265 deletions.
14 changes: 11 additions & 3 deletions lib/src/custom/custom_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import 'package:flutter_smart_dialog/src/widget/attach_dialog_widget.dart';
import '../config/enum_config.dart';
import '../data/animation_param.dart';
import '../data/base_dialog.dart';
import '../data/notify_info.dart';
import '../kit/debounce_utils.dart';
import '../smart_dialog.dart';
import '../widget/helper/smart_overlay_entry.dart';
Expand Down Expand Up @@ -262,11 +263,18 @@ class CustomDialog extends BaseDialog {

// insert the dialog carrier into the page
ViewUtils.addSafeUse(() {
NotifyInfo? firstNotify =
proxy.notifyQueue.isNotEmpty ? proxy.notifyQueue.first : null;
BuildContext overlayContext = dialogInfo.type == DialogType.custom
? DialogProxy.timelyContextCustom
: DialogProxy.timelyContextAttach;
? DialogProxy.contextCustom
: DialogProxy.contextAttach;
try {
overlay(overlayContext).insert(overlayEntry, below: proxy.entryNotify);
overlay(overlayContext).insert(
overlayEntry,
below: firstNotify != null
? firstNotify.dialog.overlayEntry
: proxy.entryLoading,
);
} catch (e) {
overlay(overlayContext).insert(overlayEntry);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/src/custom/custom_notify.dart
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,12 @@ class CustomNotify extends BaseDialog {
// insert the dialog carrier into the page
ViewUtils.addSafeUse(() {
try {
overlay(DialogProxy.timelyContextNotify).insert(
overlay(DialogProxy.contextNotify).insert(
overlayEntry,
below: proxy.entryLoading,
);
} catch (e) {
overlay(DialogProxy.timelyContextNotify).insert(overlayEntry);
overlay(DialogProxy.contextNotify).insert(overlayEntry);
}
});
}
Expand Down
2 changes: 0 additions & 2 deletions lib/src/custom/main_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,6 @@ class MainDialog {
Navigator.pop(DialogProxy.contextNavigator!);
}

await DialogProxy.instance.smartOverlayController.dismiss();

// safety await
await ViewUtils.awaitPostFrame();

Expand Down
2 changes: 1 addition & 1 deletion lib/src/custom/toast/custom_toast.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class CustomToast extends BaseDialog {
showToast() {
SmartDialog.config.toast.isExist = true;
overlayEntry.remove();
overlay(DialogProxy.timelyContextToast).insert(overlayEntry);
overlay(DialogProxy.contextToast).insert(overlayEntry);

mainDialog.show(
widget: widget,
Expand Down
39 changes: 7 additions & 32 deletions lib/src/helper/dialog_proxy.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ import '../config/smart_config.dart';
import '../data/animation_param.dart';
import '../data/notify_info.dart';
import '../init_dialog.dart';
import '../widget/helper/smart_overlay.dart';
import '../widget/helper/smart_overlay_entry.dart';
import 'show_helper.dart';

enum CloseType {
// back event
Expand Down Expand Up @@ -48,7 +46,6 @@ enum DialogType {
class DialogProxy {
late SmartConfig config;
late SmartOverlayEntry entryLoading;
late SmartOverlayEntry entryNotify;
late Queue<DialogInfo> dialogQueue;
late Queue<NotifyInfo> notifyQueue;
late CustomLoading loadingWidget;
Expand All @@ -62,14 +59,6 @@ class DialogProxy {
static late BuildContext contextNotify;
static late BuildContext contextToast;

static BuildContext get timelyContextCustom => contextCustom;

static BuildContext get timelyContextAttach => contextAttach;

static BuildContext get timelyContextNotify => contextNotify;

static BuildContext get timelyContextToast => contextToast;

static BuildContext? contextNavigator;

///set default loading widget
Expand All @@ -81,14 +70,10 @@ class DialogProxy {
///set default toast widget
late FlutterSmartNotifyStyle notifyStyle;

var smartOverlayController = SmartOverlayController();
late ShowHelper showHelper;

DialogProxy._internal() {
config = SmartConfig();
dialogQueue = ListQueue();
notifyQueue = ListQueue();
showHelper = ShowHelper(smartOverlayController);
}

void initialize(Set<SmartInitType> initType) {
Expand All @@ -98,10 +83,6 @@ class DialogProxy {
});
loadingWidget = CustomLoading(overlayEntry: entryLoading);
}

if (initType.contains(SmartInitType.notify)) {
entryNotify = SmartOverlayEntry(builder: (_) => const SizedBox.shrink());
}
}

Future<T?> show<T>({
Expand All @@ -128,8 +109,7 @@ class DialogProxy {
required bool bindPage,
required BuildContext? bindWidget,
required Rect? ignoreArea,
}) async {
await showHelper.beforeShow();
}) {
CustomDialog? dialog;
var entry = SmartOverlayEntry(
builder: (BuildContext context) => dialog!.getWidget(),
Expand Down Expand Up @@ -181,8 +161,7 @@ class DialogProxy {
required String? tag,
required bool keepSingle,
required SmartBackType backType,
}) async {
await showHelper.beforeShow();
}) {
CustomNotify? dialog;
var entry = SmartOverlayEntry(
builder: (BuildContext context) => dialog!.getWidget(),
Expand Down Expand Up @@ -239,8 +218,7 @@ class DialogProxy {
required bool useSystem,
required bool bindPage,
required BuildContext? bindWidget,
}) async {
await showHelper.beforeShow();
}) {
CustomDialog? dialog;
var entry = SmartOverlayEntry(
builder: (BuildContext context) => dialog!.getWidget(),
Expand Down Expand Up @@ -294,8 +272,7 @@ class DialogProxy {
required Duration? displayTime,
required bool backDismiss,
required Widget widget,
}) async {
await showHelper.beforeShow();
}) {
return loadingWidget.showLoading<T>(
alignment: alignment,
clickMaskDismiss: clickMaskDismiss,
Expand Down Expand Up @@ -333,8 +310,7 @@ class DialogProxy {
required bool debounce,
required SmartToastType displayType,
required Widget widget,
}) async {
await showHelper.beforeShow();
}) {
CustomToast? toast;
var entry = SmartOverlayEntry(
builder: (BuildContext context) => toast!.getWidget(),
Expand Down Expand Up @@ -366,8 +342,7 @@ class DialogProxy {
T? result,
bool force = false,
CloseType closeType = CloseType.normal,
}) async {
await showHelper.awaitShow();
}) {
if (status == SmartStatus.smart) {
var loading = config.loading.isExist;

Expand Down Expand Up @@ -423,7 +398,7 @@ class DialogProxy {
}

DialogType? type = _convertEnum(status);
if (type == null) return;
if (type == null) return null;
return CustomDialog.dismiss<T>(
type: type,
tag: tag,
Expand Down
47 changes: 0 additions & 47 deletions lib/src/helper/show_helper.dart

This file was deleted.

44 changes: 33 additions & 11 deletions lib/src/init_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import 'package:flutter_smart_dialog/src/kit/view_utils.dart';
import 'package:flutter_smart_dialog/src/widget/default/notify_alter.dart';
import 'package:flutter_smart_dialog/src/widget/default/notify_error.dart';
import 'package:flutter_smart_dialog/src/widget/default/notify_failure.dart';
import 'package:flutter_smart_dialog/src/widget/helper/smart_overlay.dart';

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

@override
Widget build(BuildContext context) {
return styleBuilder(Stack(children: [
// main widget
widget.child ?? const SizedBox.shrink(),

// dialog
SmartOverlay(
initType: initType,
controller: DialogProxy.instance.smartOverlayController,
)
]));
return styleBuilder(
Overlay(initialEntries: [
//main layout
OverlayEntry(
builder: (BuildContext context) {
if (initType.contains(SmartInitType.custom)) {
DialogProxy.contextCustom = context;
}

if (initType.contains(SmartInitType.attach)) {
DialogProxy.contextAttach = context;
}

if (initType.contains(SmartInitType.notify)) {
DialogProxy.contextNotify = context;
}

if (initType.contains(SmartInitType.toast)) {
DialogProxy.contextToast = context;
}

return widget.child ?? Container();
},
),

// if (initType.contains(SmartInitType.notify))
// DialogProxy.instance.entryNotify,

//provided separately for loading
if (initType.contains(SmartInitType.loading))
DialogProxy.instance.entryLoading,
]),
);
}

BuildContext? getNavigatorContext(Navigator navigator) {
Expand Down
Loading

0 comments on commit 716db55

Please sign in to comment.