AI_Drawing/lib/common/dialog_bean.dart
2024-06-03 15:30:15 +08:00

106 lines
2.9 KiB
Dart
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import 'package:flutter/cupertino.dart';
typedef CreateDialogWidget = Widget Function();
/// @desc 弹窗数据类
class DialogBean {
///dialog唯一标识通过 DialogBean 数据内容生成 Md5生成
late String dialogId;
///当前 dialog显示的视图。如果为空则在顶层页面
String? pageRouter;
///当前 pageRouter 对应的子页面
List<String>? innerPageRouters;
///优先级、用于显示弹窗前排序,
///但对于加入的弹窗,已经显示的情况
///[highClear] 清除已显示的弹窗,直接显示当前弹窗,该属性慎用
///[high] 回收当前已显示的弹窗,再显示高优先级弹窗,该属性慎用
DialogPriority dialogPriority;
///用于排序
late int priority;
///弹窗内部业务 widget,每次show 时动态创建。不能直接传创建好的 widget因为在 high回收时调用 pop 再 show 会出现 The following NoSuchMethodError was thrown building Builder(dirty):
CreateDialogWidget? createDialogWidget;
///弹窗类型
DialogType? dialogType;
DialogBean({
this.pageRouter,
this.innerPageRouters,
this.dialogPriority = DialogPriority.normal,
this.dialogType = DialogType.dialog,
@required this.createDialogWidget,
}) : super() {
assert(createDialogWidget!().key != null);
dialogId = (createDialogWidget!().key as ValueKey).value;
switch (dialogPriority) {
case DialogPriority.highClearAll:
priority = 30;
pageRouter = null;
break;
case DialogPriority.highClear:
priority = 20;
pageRouter = null;
break;
case DialogPriority.high:
priority = 10;
break;
case DialogPriority.normal:
priority = 1;
break;
case DialogPriority.low:
priority = 0;
break;
}
//如果内页不空,则 pageRouter不能为空
if (innerPageRouters != null) {
assert(pageRouter != null);
}
}
///是否为高优先级,带清除功能的
bool isHighClear() {
return dialogPriority == DialogPriority.highClear ||
dialogPriority == DialogPriority.highClearAll;
}
@override
String toString() {
return 'DialogBean{dialogId: $dialogId, pageRouter: $pageRouter, innerPageRouters: $innerPageRouters, priority: $priority, dialogType: $dialogType}';
}
}
enum DialogType {
///弹窗
dialog,
///底部弹窗
bottomSheet,
///底部可滑动弹窗
bottomScrollSheet,
}
enum DialogPriority {
///最高优先级,清除其它----所有弹窗(例如强制升级弹窗)
highClearAll,
///高优先级弹窗清除其它弹窗不包括highClearAll登录超时、多终端登录
highClear,
///高优先级弹窗回收normal弹窗优先显示指纹引导弹窗、提交请求弹窗
high,
///默认弹窗,按顺序弹出
normal,
///低优先级弹窗,按顺序弹出
low,
}