Skip to content

Commit 14edebb

Browse files
committed
adjust AnimationType, add scalePoint (showAttach)
1 parent 1993a55 commit 14edebb

14 files changed

+149
-42
lines changed

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,20 @@
55
- Fix [#56](https://github.com/fluttercandies/flutter_smart_dialog/issues/56)
66
- Fix [#60](https://github.com/fluttercandies/flutter_smart_dialog/issues/60)
77
- Add SmartDialogController
8+
- adjust AnimationType
9+
- fade: FadeTransition for all positions
10+
- scale: All positions are ScaleTransition
11+
- centerFade_otherSlide: The center position is the FadeTransition, and the other positions are the SlideTransition
12+
- centerScale_otherSlide: The center position is the ScaleTransition, and the other positions are the SlideTransition
13+
- add scalePoint (showAttach)
14+
15+
# [4.0.5]
16+
- adjust AnimationType
17+
- fade: FadeTransition for all positions
18+
- scale: All positions are ScaleTransition
19+
- centerFade_otherSlide: The center position is the FadeTransition, and the other positions are the SlideTransition
20+
- centerScale_otherSlide: The center position is the ScaleTransition, and the other positions are the SlideTransition
21+
- add scalePoint (showAttach)
822

923
# [4.0.3]
1024

example/lib/main.dart

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,14 @@ class SmartDialogPage extends StatelessWidget {
8484
var attachDialog = (BuildContext context) {
8585
SmartDialog.showAttach(
8686
targetContext: context,
87-
alignment: Alignment.topCenter,
88-
useSystem: true,
87+
alignment: Alignment.bottomCenter,
88+
animationType: SmartAnimationType.scale,
89+
scalePoint: Offset(100, 0),
8990
builder: (_) {
90-
return Container(width: 100, height: 100, color: Colors.red);
91+
return Column(mainAxisSize: MainAxisSize.min, children: [
92+
Container(width: 100, height: 50, color: Colors.red),
93+
Container(width: 100, height: 50, color: Colors.blue),
94+
]);
9195
},
9296
);
9397
};

lib/src/compatible/compatible_smart_dialog.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ class CompatibleSmartDialog {
124124
alignment: alignmentTemp ?? config.alignment,
125125
clickMaskDismiss: clickBgDismissTemp ?? config.clickBgDismiss,
126126
animationType: isLoadingTemp ?? config.isLoading
127-
? SmartAnimationType.centerFadeAndOtherScale
128-
: SmartAnimationType.scale,
127+
? SmartAnimationType.centerFade_otherSlide
128+
: SmartAnimationType.centerScale_otherSlide,
129129
usePenetrate: isPenetrateTemp ?? config.isPenetrate,
130130
useAnimation: isUseAnimationTemp ?? config.isUseAnimation,
131131
animationTime: animationDurationTemp ?? config.animationDuration,
@@ -279,6 +279,7 @@ class CompatibleSmartDialog {
279279
animationType: isLoadingTemp ?? false
280280
? SmartAnimationType.fade
281281
: SmartAnimationType.scale,
282+
scalePoint: null,
282283
usePenetrate: isPenetrateTemp ?? config.isPenetrate,
283284
useAnimation: isUseAnimationTemp ?? config.isUseAnimation,
284285
animationTime: animationDurationTemp ?? config.animationDuration,

lib/src/config/enum_config.dart

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,18 +79,25 @@ enum SmartToastType {
7979
///
8080
/// 可给弹窗(出现和消失)设置不同的动画类型
8181
enum SmartAnimationType {
82-
/// FadeTransition
82+
/// FadeTransition for all positions
8383
///
84-
/// 渐隐动画
84+
/// 全部位置都为渐隐动画
8585
fade,
8686

87-
/// SizeTransition
87+
/// All positions are ScaleTransition
8888
///
89-
/// 缩放动画
89+
/// 全部位置都为缩放动画
9090
scale,
9191

92-
/// 中间位置的为渐隐动画, 其他位置为位移缩放动画
93-
centerFadeAndOtherScale
92+
/// The center position is the FadeTransition, and the other positions are the SlideTransition
93+
///
94+
/// 中间位置的为渐隐动画, 其他位置为位移动画
95+
centerFade_otherSlide,
96+
97+
/// The center position is the ScaleTransition, and the other positions are the SlideTransition
98+
///
99+
/// 中间位置的为缩放, 其他位置为位移动画
100+
centerScale_otherSlide,
94101
}
95102

96103
/// The type of dialog await ending

lib/src/config/smart_config_attach.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import 'enum_config.dart';
88
class SmartConfigAttach {
99
SmartConfigAttach({
1010
this.alignment = Alignment.bottomCenter,
11-
this.animationType = SmartAnimationType.scale,
11+
this.animationType = SmartAnimationType.centerScale_otherSlide,
1212
this.animationTime = const Duration(milliseconds: 260),
1313
this.useAnimation = true,
1414
this.usePenetrate = false,

lib/src/config/smart_config_custom.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import 'enum_config.dart';
88
class SmartConfigCustom {
99
SmartConfigCustom({
1010
this.alignment = Alignment.center,
11-
this.animationType = SmartAnimationType.scale,
11+
this.animationType = SmartAnimationType.centerScale_otherSlide,
1212
this.animationTime = const Duration(milliseconds: 260),
1313
this.useAnimation = true,
1414
this.usePenetrate = false,

lib/src/custom/custom_dialog.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ class CustomDialog extends BaseDialog {
9090
required bool useAnimation,
9191
required Duration animationTime,
9292
required SmartAnimationType animationType,
93+
required Offset? scalePoint,
9394
required Color maskColor,
9495
required bool clickMaskDismiss,
9596
required bool debounce,
@@ -123,6 +124,7 @@ class CustomDialog extends BaseDialog {
123124
useAnimation: useAnimation,
124125
animationTime: animationTime,
125126
animationType: animationType,
127+
scalePoint: scalePoint,
126128
maskColor: maskColor,
127129
highlightBuilder: highlightBuilder,
128130
maskWidget: maskWidget,

lib/src/custom/main_dialog.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ class MainDialog {
7676
required bool useAnimation,
7777
required Duration animationTime,
7878
required SmartAnimationType animationType,
79+
required Offset? scalePoint,
7980
required Color maskColor,
8081
required Widget? maskWidget,
8182
required HighlightBuilder highlightBuilder,
@@ -95,6 +96,7 @@ class MainDialog {
9596
useAnimation: useAnimation,
9697
animationTime: animationTime,
9798
animationType: animationType,
99+
scalePoint: scalePoint,
98100
maskColor: maskColor,
99101
maskWidget: maskWidget,
100102
highlightBuilder: highlightBuilder,

lib/src/helper/dialog_proxy.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ class DialogProxy {
106106
required bool useAnimation,
107107
required Duration animationTime,
108108
required SmartAnimationType animationType,
109+
required Offset? scalePoint,
109110
required Color maskColor,
110111
required bool clickMaskDismiss,
111112
required Widget? maskWidget,
@@ -134,6 +135,7 @@ class DialogProxy {
134135
useAnimation: useAnimation,
135136
animationTime: animationTime,
136137
animationType: animationType,
138+
scalePoint: scalePoint,
137139
maskColor: maskColor,
138140
maskWidget: maskWidget,
139141
highlightBuilder: highlightBuilder,

lib/src/smart_dialog.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,12 @@ class SmartDialog {
190190
///
191191
/// [animationType]:For details, please refer to the [SmartAnimationType] comment
192192
///
193+
/// [scalePoint]:he zoom point of the zoom animation, the default point is the center point of the attach widget as the zoom point;
194+
/// Offset(0, 0): Use the upper left point of the control as the zoom point,
195+
/// Offset(attach widget width, 0): Use the upper right point of the control as the zoom point
196+
/// Offset(0, attach widget height): use the lower left point of the control as the zoom point,
197+
/// Offset (attach widget width, attach widget height): use the lower right point of the control as the zoom point
198+
///
193199
/// [usePenetrate]:true(the click event will penetrate mask),false(not penetration)
194200
///
195201
/// [useAnimation]:true(use the animation),false(not use)
@@ -247,6 +253,10 @@ class SmartDialog {
247253
///
248254
/// [animationType]:具体可参照[SmartAnimationType]注释
249255
///
256+
/// [scalePoint]:缩放动画的缩放点, 默认点将自定义dialog控件的中心点作为缩放点;
257+
/// Offset(0, 0): 将控件左上点作为缩放点, Offset(控件宽度, 0): 将控件右上点作为缩放点
258+
/// Offset(0, 控件高度): 将控件左下点作为缩放点, Offset(控件宽度, 控件高度): 将控件右下点作为缩放点
259+
///
250260
/// [usePenetrate]:true(点击事件将穿透遮罩),false(不穿透)
251261
///
252262
/// [useAnimation]:true(使用动画),false(不使用)
@@ -289,6 +299,7 @@ class SmartDialog {
289299
AlignmentGeometry? alignment,
290300
bool? clickMaskDismiss,
291301
SmartAnimationType? animationType,
302+
Offset? scalePoint,
292303
bool? usePenetrate,
293304
bool? useAnimation,
294305
Duration? animationTime,
@@ -333,6 +344,7 @@ class SmartDialog {
333344
alignment: alignment ?? config.attach.alignment,
334345
clickMaskDismiss: clickMaskDismiss ?? config.attach.clickMaskDismiss,
335346
animationType: animationType ?? config.attach.animationType,
347+
scalePoint: scalePoint,
336348
usePenetrate: usePenetrate ?? config.attach.usePenetrate,
337349
useAnimation: useAnimation ?? config.attach.useAnimation,
338350
animationTime: animationTime ?? config.attach.animationTime,

lib/src/util/view_utils.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class ViewUtils {
55
static bool routeSafeUse = false;
66

77
static void addSafeUse(VoidCallback callback) {
8-
var schedulerPhase = SchedulerBinding.instance.schedulerPhase;
8+
var schedulerPhase = schedulerBinding.schedulerPhase;
99
if (schedulerPhase == SchedulerPhase.persistentCallbacks) {
1010
ViewUtils.addPostFrameCallback((timeStamp) => callback());
1111
} else {
@@ -19,3 +19,5 @@ class ViewUtils {
1919
}
2020

2121
WidgetsBinding get widgetsBinding => WidgetsBinding.instance;
22+
23+
SchedulerBinding get schedulerBinding => SchedulerBinding.instance;

lib/src/widget/attach_dialog_widget.dart

Lines changed: 59 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class AttachDialogWidget extends StatefulWidget {
2525
required this.alignment,
2626
required this.usePenetrate,
2727
required this.animationType,
28+
required this.scalePoint,
2829
required this.maskColor,
2930
required this.highlightBuilder,
3031
required this.maskWidget,
@@ -60,6 +61,9 @@ class AttachDialogWidget extends StatefulWidget {
6061
/// 仅仅针对中间位置的控件
6162
final SmartAnimationType animationType;
6263

64+
/// 缩放动画的缩放点
65+
final Offset? scalePoint;
66+
6367
/// 遮罩颜色
6468
final Color maskColor;
6569

@@ -81,6 +85,7 @@ class _AttachDialogWidgetState extends State<AttachDialogWidget>
8185
//target info
8286
RectInfo? _targetRect;
8387
BuildContext? _childContext;
88+
Alignment? _scaleAlignment;
8489
late Axis _axis;
8590
late double _postFrameOpacity;
8691

@@ -202,29 +207,57 @@ class _AttachDialogWidgetState extends State<AttachDialogWidget>
202207

203208
Widget _buildBodyAnimation(Widget child) {
204209
var animation = CurvedAnimation(parent: _ctrlBody, curve: Curves.linear);
205-
var transition = widget.alignment == Alignment.center
206-
//中间弹窗动画使用缩放
207-
? ScaleTransition(scale: animation, child: child)
208-
//其它的都使用位移动画
209-
: SizeTransition(axis: _axis, sizeFactor: _ctrlBody, child: child);
210-
211-
bool useFade = (widget.animationType == SmartAnimationType.fade) ||
212-
(widget.animationType == SmartAnimationType.centerFadeAndOtherScale &&
213-
widget.alignment == Alignment.center);
214-
return useFade
215-
? FadeTransition(opacity: animation, child: child)
216-
: transition;
210+
var type = widget.animationType;
211+
Widget animationWidget = FadeTransition(opacity: animation, child: child);
212+
213+
//select different animation
214+
if (type == SmartAnimationType.fade) {
215+
animationWidget = FadeTransition(opacity: animation, child: child);
216+
} else if (type == SmartAnimationType.scale) {
217+
animationWidget = ScaleTransition(
218+
alignment: _scaleAlignment ?? Alignment(0, 0),
219+
scale: animation,
220+
child: child,
221+
);
222+
} else if (type == SmartAnimationType.centerFade_otherSlide) {
223+
if (widget.alignment == Alignment.center) {
224+
animationWidget = FadeTransition(opacity: animation, child: child);
225+
} else {
226+
animationWidget = SizeTransition(
227+
axis: _axis,
228+
sizeFactor: _ctrlBody,
229+
child: child,
230+
);
231+
}
232+
} else if (type == SmartAnimationType.centerScale_otherSlide) {
233+
if (widget.alignment == Alignment.center) {
234+
animationWidget = ScaleTransition(
235+
alignment: _scaleAlignment ?? Alignment(0, 0),
236+
scale: animation,
237+
child: child,
238+
);
239+
} else {
240+
animationWidget = SizeTransition(
241+
axis: _axis,
242+
sizeFactor: _ctrlBody,
243+
child: child,
244+
);
245+
}
246+
}
247+
248+
return animationWidget;
217249
}
218250

219-
///处理下动画方向及其位置
251+
/// 处理: 动画方向及其位置, 缩放动画的缩放点
220252
void _handleAnimatedAndLocation() {
253+
final childSize = (_childContext!.findRenderObject() as RenderBox).size;
254+
255+
//动画方向及其位置
221256
_axis = Axis.vertical;
222257
final alignment = widget.alignment;
223258
var offset = targetOffset;
224259
var size = targetSize;
225260
final screen = MediaQuery.of(context).size;
226-
final childSize = (_childContext!.findRenderObject() as RenderBox).size;
227-
228261
if (alignment == Alignment.topLeft) {
229262
_targetRect = RectInfo(
230263
bottom: screen.height - offset.dy,
@@ -276,6 +309,17 @@ class _AttachDialogWidgetState extends State<AttachDialogWidget>
276309
);
277310
}
278311

312+
//缩放动画的缩放点
313+
if (widget.scalePoint != null) {
314+
var halfWidth = childSize.width / 2;
315+
var halfHeight = childSize.height / 2;
316+
var scaleDx = widget.scalePoint!.dx;
317+
var scaleDy = widget.scalePoint!.dy;
318+
var rateX = (scaleDx - halfWidth) / halfWidth;
319+
var rateY = (scaleDy - halfHeight) / halfHeight;
320+
_scaleAlignment = Alignment(rateX, rateY);
321+
}
322+
279323
//第一帧后恢复透明度,同时重置位置信息
280324
_postFrameOpacity = 1;
281325
setState(() {});

lib/src/widget/smart_dialog_widget.dart

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -129,20 +129,37 @@ class _SmartDialogWidgetState extends State<SmartDialogWidget>
129129
}
130130

131131
Widget _buildBodyAnimation() {
132+
var child = widget.child;
132133
var animation = CurvedAnimation(parent: _ctrlBody, curve: Curves.linear);
133134
var tw = Tween<Offset>(begin: _offset, end: Offset.zero);
134-
var transition = widget.alignment == Alignment.center
135-
//中间弹窗动画使用缩放
136-
? ScaleTransition(scale: animation, child: widget.child)
137-
//其它的都使用位移动画
138-
: SlideTransition(position: tw.animate(_ctrlBody), child: widget.child);
139-
140-
bool useFade = (widget.animationType == SmartAnimationType.fade) ||
141-
(widget.animationType == SmartAnimationType.centerFadeAndOtherScale &&
142-
widget.alignment == Alignment.center);
143-
return useFade
144-
? FadeTransition(opacity: animation, child: widget.child)
145-
: transition;
135+
var type = widget.animationType;
136+
Widget animationWidget = FadeTransition(opacity: animation, child: child);
137+
138+
//select different animation
139+
if (type == SmartAnimationType.fade) {
140+
animationWidget = FadeTransition(opacity: animation, child: child);
141+
} else if (type == SmartAnimationType.scale) {
142+
animationWidget = ScaleTransition(scale: animation, child: child);
143+
} else if (type == SmartAnimationType.centerFade_otherSlide) {
144+
if (widget.alignment == Alignment.center) {
145+
animationWidget = FadeTransition(opacity: animation, child: child);
146+
} else {
147+
animationWidget = SlideTransition(
148+
position: tw.animate(_ctrlBody),
149+
child: child,
150+
);
151+
}
152+
} else if (type == SmartAnimationType.centerScale_otherSlide) {
153+
if (widget.alignment == Alignment.center) {
154+
animationWidget = ScaleTransition(scale: animation, child: child);
155+
} else {
156+
animationWidget = SlideTransition(
157+
position: tw.animate(_ctrlBody),
158+
child: child,
159+
);
160+
}
161+
}
162+
return animationWidget;
146163
}
147164

148165
///处理下内容widget动画方向

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.3.5
6+
version: 4.3.6
77
homepage: https://github.com/fluttercandies/flutter_smart_dialog
88
#flutter pub publish --server=https://pub.dartlang.org
99

0 commit comments

Comments
 (0)