Skip to content

Commit

Permalink
optimize loading #137
Browse files Browse the repository at this point in the history
  • Loading branch information
xdd666t committed Jul 2, 2023
1 parent b13fabd commit ac5a720
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 28 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
* optimize nonAnimationTypes
* toast add some param
* fix [#135](https://github.com/fluttercandies/flutter_smart_dialog/issues/135)
* optimize loading [#137](https://github.com/fluttercandies/flutter_smart_dialog/issues/137)
* optimize 'show debug point'


# [4.9.0]
* Breaking Change
Expand Down
8 changes: 6 additions & 2 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,12 @@ class SmartDialogPage extends StatelessWidget {
}

void _showLoading() async {
SmartDialog.showLoading();
await Future.delayed(const Duration(seconds: 2));
SmartDialog.showLoading(msg: "test one");
await Future.delayed(const Duration(seconds: 1));
SmartDialog.showLoading(msg: "test two");
await Future.delayed(const Duration(seconds: 1));
SmartDialog.showLoading(msg: "test three");
await Future.delayed(const Duration(seconds: 1));
SmartDialog.dismiss();
}

Expand Down
5 changes: 5 additions & 0 deletions lib/src/config/enum_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,11 @@ enum SmartNonAnimationType {
/// 注: ColorFiltered和FadeTransition动画组件冲突, 会造成频闪bug,
/// flutter2.10.5和flutter3.3.5能稳定复现,flutter3.0.5版本则不存在这个问题
highlightMask_nonAnimation,

/// Continuously call Loading, no flickering animation
///
/// 连续调用Loading, 无闪烁动画
continueLoading_nonAnimation,
}

/// The alignment effect when the attach dialog selects different alignment properties
Expand Down
1 change: 1 addition & 0 deletions lib/src/config/smart_config_loading.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class SmartConfigLoading {
this.maskTriggerType = SmartMaskTriggerType.up,
this.nonAnimationTypes = const [
SmartNonAnimationType.routeClose_nonAnimation,
SmartNonAnimationType.continueLoading_nonAnimation,
],
this.isExist = false,
});
Expand Down
10 changes: 9 additions & 1 deletion lib/src/custom/custom_loading.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,18 @@ class CustomLoading extends BaseDialog {
_canDismissCallback?.call();
});

List<SmartNonAnimationType> nonAnimations = [];
var continueLoading = SmartNonAnimationType.continueLoading_nonAnimation;
if (SmartDialog.config.isExistLoading &&
nonAnimationTypes.contains(continueLoading)) {
nonAnimations.addAll(nonAnimationTypes);
nonAnimations.add(SmartNonAnimationType.openDialog_nonAnimation);
}

return mainDialog.show<T>(
widget: widget,
animationType: animationType,
nonAnimationTypes: nonAnimationTypes,
nonAnimationTypes: nonAnimations,
animationBuilder: animationBuilder,
alignment: alignment,
maskColor: maskColor,
Expand Down
8 changes: 0 additions & 8 deletions lib/src/data/base_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,6 @@ import '../helper/dialog_proxy.dart';
abstract class BaseController {
Future<void> dismiss({CloseType closeType = CloseType.normal});

bool judgeOpenDialogType(SmartNonAnimationType nonAnimationType) {
if (nonAnimationType == SmartNonAnimationType.openDialog_nonAnimation) {
return true;
}

return false;
}

bool judgeDismissDialogType(
CloseType closeType,
SmartNonAnimationType nonAnimationType,
Expand Down
20 changes: 12 additions & 8 deletions lib/src/widget/attach_dialog_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,12 @@ class _AttachDialogWidgetState extends State<AttachDialogWidget>

void _resetState() {
var startTime = widget.animationTime;
for (var nonAnimationType in widget.nonAnimationTypes) {
if (widget.controller.judgeOpenDialogType(nonAnimationType)) {
startTime = Duration.zero;
}
var openDialog = SmartNonAnimationType.openDialog_nonAnimation;
if (widget.nonAnimationTypes.contains(openDialog)) {
startTime = Duration.zero;
}
if (!widget.useAnimation) {
startTime = Duration.zero;
}

if (_maskController == null) {
Expand Down Expand Up @@ -185,7 +187,7 @@ class _AttachDialogWidgetState extends State<AttachDialogWidget>
alignment: widget.alignment,
originChild: _child,
builder: (Widget child) {
return widget.useAnimation ? _buildBodyAnimation(child) : child;
return _buildBodyAnimation(child);
},
belowBuilder: (targetOffset, targetSize) {
return [
Expand Down Expand Up @@ -319,16 +321,18 @@ class _AttachDialogWidgetState extends State<AttachDialogWidget>
endTime = Duration.zero;
}
}
if (!widget.useAnimation) {
endTime = Duration.zero;
}

_maskController!.duration = endTime;
_bodyController.duration = endTime;

//over animation
_maskController!.reverse();
_bodyController.reverse();
_animationParam?.onDismiss?.call();
if (widget.useAnimation) {
await Future.delayed(endTime);
}
await Future.delayed(endTime);
}

@override
Expand Down
20 changes: 12 additions & 8 deletions lib/src/widget/smart_dialog_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,12 @@ class _SmartDialogWidgetState extends State<SmartDialogWidget>

void _resetState() {
var startTime = widget.animationTime;
for (var nonAnimationType in widget.nonAnimationTypes) {
if (widget.controller.judgeOpenDialogType(nonAnimationType)) {
startTime = Duration.zero;
}
var openDialog = SmartNonAnimationType.openDialog_nonAnimation;
if (widget.nonAnimationTypes.contains(openDialog)) {
startTime = Duration.zero;
}
if (!widget.useAnimation) {
startTime = Duration.zero;
}

if (_maskController == null) {
Expand Down Expand Up @@ -154,7 +156,7 @@ class _SmartDialogWidgetState extends State<SmartDialogWidget>
//内容Widget动画
Container(
alignment: widget.alignment,
child: widget.useAnimation ? _buildBodyAnimation() : widget.child,
child: _buildBodyAnimation(),
),
]),
);
Expand Down Expand Up @@ -215,16 +217,18 @@ class _SmartDialogWidgetState extends State<SmartDialogWidget>
endTime = Duration.zero;
}
}
if (!widget.useAnimation) {
endTime = Duration.zero;
}

_maskController!.duration = endTime;
_bodyController.duration = endTime;

//over animation
_maskController!.reverse();
_bodyController.reverse();
_animationParam?.onDismiss?.call();
if (widget.useAnimation) {
await Future.delayed(endTime);
}
await Future.delayed(endTime);
}

@override
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description:
An elegant Flutter Dialog solution,
Easily implement Toast, Loading and custom Dialog,
Make the use of the dialog easier!
version: 4.9.2
version: 4.9.3
homepage: https://github.com/fluttercandies/flutter_smart_dialog
# flutter pub publish --server=https://pub.dartlang.org

Expand Down

0 comments on commit ac5a720

Please sign in to comment.