-
-
Notifications
You must be signed in to change notification settings - Fork 171
Expand file tree
/
Copy patheffects.dart
More file actions
118 lines (103 loc) · 2.83 KB
/
effects.dart
File metadata and controls
118 lines (103 loc) · 2.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import 'package:flutter/widgets.dart';
import 'package:flutter_animate/flutter_animate.dart';
typedef AnimEffect<T> = Effect<T>;
@immutable
class SizeEffect extends Effect<double> {
const SizeEffect({
super.delay,
super.duration,
super.curve,
double? begin,
double? end,
this.clipBehavior = Clip.hardEdge,
}) : super(
begin: begin ?? (end == null ? defaultValue : neutralValue),
end: end ?? neutralValue,
);
/// {@template SizeEffect.clipBehavior}
/// The clip behavior of the size transition.
/// Defaults to [Clip.hardEdge].
/// Set to [Clip.none] to prevent clipping of focus rings and other
/// content that extends beyond the widget's boundary.
/// {@endtemplate}
final Clip clipBehavior;
@override
Widget build(
BuildContext context,
Widget child,
AnimationController controller,
EffectEntry entry,
) {
return ShadSizeTransition(
sizeFactor: buildAnimation(controller, entry),
clipBehavior: clipBehavior,
child: child,
);
}
static const neutralValue = 1.0;
static const defaultValue = 0.0;
}
/// {@template ShadSizeTransition}
/// A custom size transition widget that supports [clipBehavior].
///
/// This is similar to Flutter's [SizeTransition] but with configurable
/// clip behavior to allow focus rings and other content to extend beyond
/// the widget's boundary during animation.
/// {@endtemplate}
class ShadSizeTransition extends AnimatedWidget {
/// {@macro ShadSizeTransition}
const ShadSizeTransition({
super.key,
required Animation<double> sizeFactor,
this.clipBehavior = Clip.hardEdge,
this.child,
}) : super(listenable: sizeFactor);
final Clip clipBehavior;
final Widget? child;
Animation<double> get sizeFactor => listenable as Animation<double>;
@override
Widget build(BuildContext context) {
final result = Align(
alignment: AlignmentDirectional.topStart,
heightFactor: sizeFactor.value,
child: child,
);
if (clipBehavior == Clip.none) {
return result;
}
return ClipRect(
clipBehavior: clipBehavior,
child: result,
);
}
}
@immutable
class PaddingEffect extends Effect<double> {
const PaddingEffect({
required this.padding,
super.delay,
super.duration,
super.curve,
double? begin,
double? end,
}) : super(
begin: begin ?? (end == null ? defaultValue : neutralValue),
end: end ?? neutralValue,
);
@override
Widget build(
BuildContext context,
Widget child,
AnimationController controller,
EffectEntry entry,
) {
final animation = buildAnimation(controller, entry);
return Padding(
padding: padding * animation.value,
child: child,
);
}
final EdgeInsetsGeometry padding;
static const neutralValue = 1.0;
static const defaultValue = 0.0;
}