Skip to content

Commit 0eb7719

Browse files
committed
add 'SmartAttachAlignmentType'
1 parent 8b8acce commit 0eb7719

File tree

7 files changed

+92
-29
lines changed

7 files changed

+92
-29
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
- Toast 'displayType' add 'onlyRefresh'
66
- Compatible with flutter_boost
77
- Add 'SmartAttachAlignmentType'
8+
- Add 'SmartInitType'
89

910

1011
# [4.6.x]

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Language: English | [中文](https://juejin.cn/post/7026150456673959943)
44

55
Migrate doc:[3.x migrate 4.0](https://github.com/fluttercandies/flutter_smart_dialog/blob/master/docs/3.x%20migrate%204.0.md) | [3.x 迁移 4.0](https://juejin.cn/post/7093867453012246565)
66

7-
Flutter 2:Please use `flutter_smart_dialog: 4.2.1`
7+
Flutter 2:Please use `flutter_smart_dialog: 4.2.2`
88

99
Flutter 3:Please use the latest version
1010

lib/src/config/enum_config.dart

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
2-
31
enum SmartStatus {
42
/// close single dialog:loading(showToast),custom(show)or attach(showAttach)
53
///
@@ -216,4 +214,24 @@ enum SmartAttachAlignmentType {
216214
/// attach dialog对齐目标控件外边缘, 注意: Alignment.centerXxx不受影响, 依旧是中心点对齐;
217215
/// Alignment.bottomLeft/topLeft(dialog右边边缘对齐目标控件左侧边缘), Alignment.bottomRight/topRight((dialog左边边缘对齐目标控件右侧边缘))
218216
outside,
219-
}
217+
}
218+
219+
/// The initialization type can be dynamically set, which is suitable for some special scenarios;
220+
/// for example: for a desktop application, initializing the global only needs to initialize the Attach Dialog,
221+
/// and initializing a block area does not need to initialize the Attach Dialog
222+
///
223+
/// 可动态设置初始化类型, 适用于一些特殊场景;
224+
/// 例如: 某桌面端应用, 初始化全局只需要初始化Attach Dialog, 初始化某块区域不需要初始化Attach Dialog
225+
enum SmartInitType {
226+
/// init CustomDialog (show)
227+
custom,
228+
229+
/// init AttachDialog (showAttach)
230+
attach,
231+
232+
/// init Loading (showLoading)
233+
loading,
234+
235+
/// init Toast (showToast)
236+
toast,
237+
}

lib/src/custom/custom_dialog.dart

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -272,10 +272,25 @@ class CustomDialog extends BaseDialog {
272272

273273
// insert the dialog carrier into the page
274274
ViewUtils.addSafeUse(() {
275-
Overlay.of(DialogProxy.contextOverlay)!.insert(
276-
overlayEntry,
277-
below: proxy.entryLoading,
278-
);
275+
if (dialogInfo.type == DialogType.custom) {
276+
try {
277+
Overlay.of(DialogProxy.contextCustom)!.insert(
278+
overlayEntry,
279+
below: proxy.entryLoading,
280+
);
281+
} catch (e) {
282+
Overlay.of(DialogProxy.contextCustom)!.insert(overlayEntry);
283+
}
284+
} else {
285+
try {
286+
Overlay.of(DialogProxy.contextAttach)!.insert(
287+
overlayEntry,
288+
below: proxy.entryLoading,
289+
);
290+
} catch (e) {
291+
Overlay.of(DialogProxy.contextAttach)!.insert(overlayEntry);
292+
}
293+
}
279294
});
280295
}
281296

@@ -287,8 +302,8 @@ class CustomDialog extends BaseDialog {
287302
var debounceTime = type == DialogType.dialog
288303
? SmartDialog.config.custom.debounceTime
289304
: SmartDialog.config.attach.debounceTime;
290-
var prohibit = proxy.dialogLastTime != null &&
291-
now.difference(proxy.dialogLastTime!) < debounceTime;
305+
var prohibit =
306+
proxy.dialogLastTime != null && now.difference(proxy.dialogLastTime!) < debounceTime;
292307
proxy.dialogLastTime = now;
293308
if (prohibit) return false;
294309

@@ -312,9 +327,7 @@ class CustomDialog extends BaseDialog {
312327
bool force = false,
313328
CloseType closeType = CloseType.normal,
314329
}) {
315-
if (type == DialogType.dialog ||
316-
type == DialogType.custom ||
317-
type == DialogType.attach) {
330+
if (type == DialogType.dialog || type == DialogType.custom || type == DialogType.attach) {
318331
return _closeSingle<T>(
319332
type: type,
320333
tag: tag,

lib/src/helper/dialog_proxy.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ class DialogProxy {
4444

4545
static DialogProxy get instance => _instance ??= DialogProxy._internal();
4646

47-
static late BuildContext contextOverlay;
47+
static late BuildContext contextCustom;
48+
static late BuildContext contextAttach;
4849
static BuildContext? contextNavigator;
4950

5051
///set default loading widget

lib/src/init_dialog.dart

Lines changed: 44 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import 'package:flutter/material.dart';
2+
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
23
import 'package:flutter_smart_dialog/src/helper/navigator_observer.dart';
34
import 'package:flutter_smart_dialog/src/util/view_utils.dart';
45
import 'package:flutter_smart_dialog/src/widget/toast_widget.dart';
@@ -19,6 +20,7 @@ class FlutterSmartDialog extends StatefulWidget {
1920
this.toastBuilder,
2021
this.loadingBuilder,
2122
this.styleBuilder,
23+
this.initType,
2224
}) : super(key: key);
2325

2426
final Widget? child;
@@ -32,6 +34,9 @@ class FlutterSmartDialog extends StatefulWidget {
3234
///Compatible with cupertino style
3335
final FlutterSmartStyleBuilder? styleBuilder;
3436

37+
///inti type
38+
final Set<SmartInitType>? initType;
39+
3540
@override
3641
_FlutterSmartDialogState createState() => _FlutterSmartDialogState();
3742

@@ -50,6 +55,8 @@ class FlutterSmartDialog extends StatefulWidget {
5055
FlutterSmartLoadingBuilder? loadingBuilder,
5156
//Compatible with cupertino style
5257
FlutterSmartStyleBuilder? styleBuilder,
58+
//init type
59+
Set<SmartInitType>? initType,
5360
}) {
5461
MonitorPopRoute.instance;
5562

@@ -59,6 +66,7 @@ class FlutterSmartDialog extends StatefulWidget {
5966
toastBuilder: toastBuilder,
6067
loadingBuilder: loadingBuilder,
6168
styleBuilder: styleBuilder,
69+
initType: initType,
6270
child: child,
6371
)
6472
: builder(
@@ -67,6 +75,7 @@ class FlutterSmartDialog extends StatefulWidget {
6775
toastBuilder: toastBuilder,
6876
loadingBuilder: loadingBuilder,
6977
styleBuilder: styleBuilder,
78+
initType: initType,
7079
child: child,
7180
),
7281
);
@@ -75,6 +84,9 @@ class FlutterSmartDialog extends StatefulWidget {
7584
}
7685

7786
class _FlutterSmartDialogState extends State<FlutterSmartDialog> {
87+
late FlutterSmartStyleBuilder styleBuilder;
88+
late Set<SmartInitType> initType;
89+
7890
@override
7991
void initState() {
8092
ViewUtils.addSafeUse(() {
@@ -99,34 +111,52 @@ class _FlutterSmartDialogState extends State<FlutterSmartDialog> {
99111
proxy.toastBuilder = widget.toastBuilder ?? defaultToast;
100112
proxy.loadingBuilder = widget.loadingBuilder ?? defaultLoading;
101113

114+
// init param
115+
styleBuilder = widget.styleBuilder ??
116+
(Widget child) {
117+
return Material(color: Colors.transparent, child: child);
118+
};
119+
initType = widget.initType ??
120+
{SmartInitType.custom, SmartInitType.attach, SmartInitType.loading, SmartInitType.toast};
121+
102122
super.initState();
103123
}
104124

105125
@override
106126
Widget build(BuildContext context) {
107-
return widget.styleBuilder == null
108-
? Material(color: Colors.transparent, child: _buildOverlay())
109-
: widget.styleBuilder!.call(_buildOverlay());
110-
}
111-
112-
Widget _buildOverlay() {
113-
return Overlay(initialEntries: [
127+
return styleBuilder(Overlay(initialEntries: [
114128
//main layout
115129
OverlayEntry(
116130
builder: (BuildContext context) => widget.child ?? Container(),
117131
),
118132

119133
//provided separately for custom dialog
120-
OverlayEntry(builder: (BuildContext context) {
121-
DialogProxy.contextOverlay = context;
122-
return Container();
123-
}),
134+
if (initType.contains(SmartInitType.custom) && !initType.contains(SmartInitType.attach))
135+
OverlayEntry(builder: (BuildContext context) {
136+
DialogProxy.contextCustom = context;
137+
return Container();
138+
}),
139+
140+
//provided separately for attach dialog
141+
if (initType.contains(SmartInitType.attach) && !initType.contains(SmartInitType.custom))
142+
OverlayEntry(builder: (BuildContext context) {
143+
DialogProxy.contextAttach = context;
144+
return Container();
145+
}),
146+
147+
//provided separately for custom dialog and attach dialog
148+
if (initType.contains(SmartInitType.custom) && initType.contains(SmartInitType.attach))
149+
OverlayEntry(builder: (BuildContext context) {
150+
DialogProxy.contextCustom = context;
151+
DialogProxy.contextAttach = context;
152+
return Container();
153+
}),
124154

125155
//provided separately for loading
126-
DialogProxy.instance.entryLoading,
156+
if (initType.contains(SmartInitType.loading)) DialogProxy.instance.entryLoading,
127157

128158
//provided separately for toast
129-
DialogProxy.instance.entryToast,
130-
]);
159+
if (initType.contains(SmartInitType.toast)) DialogProxy.instance.entryToast,
160+
]));
131161
}
132162
}

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ description:
33
An elegant Flutter Dialog solution,
44
Easily implement Toast, Loading and custom Dialog,
55
Make the use of the dialog easier!
6-
version: 4.7.1
6+
version: 4.7.2
77
homepage: https://github.com/fluttercandies/flutter_smart_dialog
88
# flutter pub publish --server=https://pub.dartlang.org
99

0 commit comments

Comments
 (0)