Skip to content

Commit

Permalink
add onBack feature, delete CompatibleSmartDialog, delete SmartConfigC…
Browse files Browse the repository at this point in the history
…ustom/SmartConfigAttach/SmartConfigLoading backDismiss
  • Loading branch information
xdd666t committed Sep 16, 2024
1 parent 716db55 commit 8b71392
Show file tree
Hide file tree
Showing 18 changed files with 198 additions and 731 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# [4.9.8+x]
* SmartDialog.config.checkExist() adjust to SmartDialog.checkExist()
* Fix [#209](https://github.com/fluttercandies/flutter_smart_dialog/issues/209)
* Revert the initialization implementation
* Add onBack feature
* Break change
* Delete CompatibleSmartDialog
* Delete SmartConfigCustom/SmartConfigAttach/SmartConfigLoading backDismiss

* # [4.9.7+x]
* optimize bindWidget, when bindWidget is not null, bindPage will be automatically set to false.
Expand Down
556 changes: 0 additions & 556 deletions lib/src/compatible/compatible_smart_dialog.dart

This file was deleted.

100 changes: 0 additions & 100 deletions lib/src/compatible/smart_config_compatible.dart

This file was deleted.

7 changes: 0 additions & 7 deletions lib/src/config/smart_config.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:flutter_smart_dialog/src/compatible/smart_config_compatible.dart';

import '../kit/dialog_kit.dart';

Expand Down Expand Up @@ -48,12 +47,6 @@ class SmartConfig {
return DialogKit.instance.checkExist(tag: tag, dialogTypes: dialogTypes);
}

/// Compatible with older versions
///
/// 兼容老版本配置
@Deprecated("5.0 will be deleted and is not recommended for continued use")
SmartConfigCompatible compatible = SmartConfigCompatible();

/// whether custom dialog,attach and loading exist on the screen
///
/// 自定义dialog,attach或loading,是否存在在界面上
Expand Down
8 changes: 8 additions & 0 deletions lib/src/config/smart_config_attach.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class SmartConfigAttach {
SmartNonAnimationType.highlightMask_nonAnimation,
],
this.attachAlignmentType = SmartAttachAlignmentType.center,
this.backType = SmartBackType.normal,
this.isExist = false,
});

Expand Down Expand Up @@ -112,6 +113,7 @@ class SmartConfigAttach {
///
/// true(返回事件将关闭loading,但是不会关闭页面),false(返回事件不会关闭loading,也不会关闭页面),
/// 你仍然可以使用dismiss方法来关闭dialog
@Deprecated("please use backType")
final bool backDismiss;

/// Bind the dialog to the current page, the bound page is not on the top of the stack,
Expand Down Expand Up @@ -144,6 +146,12 @@ class SmartConfigAttach {
/// attach dialog选择不同alignment属性时的对齐效果, 具体说明请参照[SmartAttachAlignmentType]
final SmartAttachAlignmentType attachAlignmentType;

/// For different processing types of return events,
/// please refer to the description of [SmartBackType] for details
///
/// 对于返回事件不同的处理类型, 具体可参照[SmartBackType]说明
final SmartBackType backType;

/// whether attach dialog(showAttach()) exist on the screen
///
/// attach dialog(showAttach()),是否存在在界面上
Expand Down
8 changes: 8 additions & 0 deletions lib/src/config/smart_config_custom.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class SmartConfigCustom {
this.nonAnimationTypes = const [
SmartNonAnimationType.routeClose_nonAnimation,
],
this.backType = SmartBackType.normal,
this.isExist = false,
});

Expand Down Expand Up @@ -110,6 +111,7 @@ class SmartConfigCustom {
///
/// true(返回事件将关闭loading,但是不会关闭页面),false(返回事件不会关闭loading,也不会关闭页面),
/// 你仍然可以使用dismiss方法来关闭dialog
@Deprecated("please use backType")
final bool backDismiss;

/// Bind the dialog to the current page, the bound page is not on the top of the stack,
Expand All @@ -136,6 +138,12 @@ class SmartConfigCustom {
/// 对于不同的场景, 可动态关闭弹窗动画, 具体请参照[SmartNonAnimationType]
final List<SmartNonAnimationType> nonAnimationTypes;

/// For different processing types of return events,
/// please refer to the description of [SmartBackType] for details
///
/// 对于返回事件不同的处理类型, 具体可参照[SmartBackType]说明
final SmartBackType backType;

/// whether custom dialog(show()) exist on the screen
///
/// 自定义dialog(show()),是否存在在界面上
Expand Down
16 changes: 7 additions & 9 deletions lib/src/config/smart_config_loading.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ class SmartConfigLoading {
this.usePenetrate = false,
this.maskColor = const Color.fromRGBO(0, 0, 0, 0.46),
this.maskWidget,
this.backDismiss = true,
this.clickMaskDismiss = false,
this.leastLoadingTime = const Duration(milliseconds: 0),
this.awaitOverType = SmartAwaitOverType.dialogDismiss,
Expand All @@ -23,6 +22,7 @@ class SmartConfigLoading {
SmartNonAnimationType.routeClose_nonAnimation,
SmartNonAnimationType.continueLoading_nonAnimation,
],
this.backType = SmartBackType.normal,
this.isExist = false,
});

Expand Down Expand Up @@ -84,14 +84,6 @@ class SmartConfigLoading {
/// 遮罩Widget,可高度自定义你自己的遮罩背景:[usePenetrate]设置为true,该参数失效
final Widget? maskWidget;

/// true(the back event will close the loading but not close the page),
/// false(the back event not close the loading and not close page),
/// you still can use the dismiss method to close the loading
///
/// true(返回事件将关闭loading,但是不会关闭页面),false(返回事件不会关闭loading,也不会关闭页面),
/// 你仍然可以使用dismiss方法来关闭loading
final bool backDismiss;

/// true(dialog will be closed after click background),false(not close)
///
/// true(点击遮罩关闭dialog),false(不关闭)
Expand Down Expand Up @@ -119,6 +111,12 @@ class SmartConfigLoading {
/// 对于不同的场景, 可动态关闭弹窗动画, 具体请参照[SmartNonAnimationType]
final List<SmartNonAnimationType> nonAnimationTypes;

/// For different processing types of return events,
/// please refer to the description of [SmartBackType] for details
///
/// 对于返回事件不同的处理类型, 具体可参照[SmartBackType]说明
final SmartBackType backType;

/// whether loading(showLoading()) exist on the screen
///
/// loading(showLoading())是否存在在界面上
Expand Down
27 changes: 15 additions & 12 deletions lib/src/custom/custom_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import '../data/animation_param.dart';
import '../data/base_dialog.dart';
import '../data/notify_info.dart';
import '../kit/debounce_utils.dart';
import '../kit/typedef.dart';
import '../smart_dialog.dart';
import '../widget/helper/smart_overlay_entry.dart';

Expand All @@ -39,21 +40,21 @@ class CustomDialog extends BaseDialog {
required VoidCallback? onMask,
required Duration? displayTime,
required String? tag,
required bool backDismiss,
required bool keepSingle,
required bool permanent,
required bool useSystem,
required bool bindPage,
required BuildContext? bindWidget,
required Rect? ignoreArea,
required SmartBackType? backType,
required SmartOnBack? onBack,
}) {
if (DebounceUtils.instance.banContinue(DebounceType.custom, debounce)) {
return Future.value(null);
}

final dialogInfo = _handleMustOperate(
tag: tag,
backDismiss: backDismiss,
keepSingle: keepSingle,
debounce: debounce,
type: DialogType.custom,
Expand All @@ -62,6 +63,8 @@ class CustomDialog extends BaseDialog {
bindPage: bindPage,
bindWidget: bindWidget,
displayTime: displayTime,
backType: backType,
onBack: onBack,
);
return mainDialog.show<T>(
widget: widget,
Expand Down Expand Up @@ -116,20 +119,20 @@ class CustomDialog extends BaseDialog {
required VoidCallback? onDismiss,
required Duration? displayTime,
required String? tag,
required bool backDismiss,
required bool keepSingle,
required bool permanent,
required bool useSystem,
required bool bindPage,
required BuildContext? bindWidget,
required SmartBackType? backType,
required SmartOnBack? onBack,
}) {
if (DebounceUtils.instance.banContinue(DebounceType.attach, debounce)) {
return Future.value(null);
}

final dialogInfo = _handleMustOperate(
tag: tag,
backDismiss: backDismiss,
keepSingle: keepSingle,
debounce: debounce,
type: DialogType.attach,
Expand All @@ -138,6 +141,8 @@ class CustomDialog extends BaseDialog {
bindPage: bindPage,
bindWidget: bindWidget,
displayTime: displayTime,
backType: backType,
onBack: onBack,
);
return mainDialog.showAttach<T>(
targetContext: targetContext,
Expand Down Expand Up @@ -197,7 +202,6 @@ class CustomDialog extends BaseDialog {

DialogInfo _handleMustOperate({
required String? tag,
required bool backDismiss,
required bool keepSingle,
required bool debounce,
required DialogType type,
Expand All @@ -206,6 +210,8 @@ class CustomDialog extends BaseDialog {
required bool bindPage,
required BuildContext? bindWidget,
required Duration? displayTime,
required SmartBackType? backType,
required SmartOnBack? onBack,
}) {
SmartDialog.config.custom.isExist = DialogType.custom == type;
SmartDialog.config.attach.isExist = DialogType.attach == type;
Expand All @@ -216,14 +222,15 @@ class CustomDialog extends BaseDialog {
if (singleDialogInfo == null) {
singleDialogInfo = DialogInfo(
dialog: this,
backDismiss: backDismiss,
type: type,
tag: tag ?? SmartTag.keepSingle,
permanent: permanent,
useSystem: useSystem,
bindPage: bindPage,
route: RouteRecord.curRoute,
bindWidget: bindWidget,
backType: backType,
onBack: onBack,
);
_pushDialog(singleDialogInfo);
}
Expand All @@ -235,14 +242,15 @@ class CustomDialog extends BaseDialog {
// handle dialog stack
dialogInfo = DialogInfo(
dialog: this,
backDismiss: backDismiss,
type: type,
tag: tag,
permanent: permanent,
useSystem: useSystem,
bindPage: bindPage,
route: RouteRecord.curRoute,
bindWidget: bindWidget,
backType: backType,
onBack: onBack,
);
_pushDialog(dialogInfo);
}
Expand Down Expand Up @@ -419,11 +427,6 @@ class CustomDialog extends BaseDialog {
}
}

//handle prohibiting back event
if (info != null && (!info.backDismiss && closeType == CloseType.back)) {
return null;
}

return info;
}
}
Loading

0 comments on commit 8b71392

Please sign in to comment.