-
Notifications
You must be signed in to change notification settings - Fork 62
/
sliver_animated_paint_extent.dart
89 lines (73 loc) · 2.18 KB
/
sliver_animated_paint_extent.dart
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
import 'package:flutter/widgets.dart';
import 'rendering/sliver_animated_paint_extent.dart';
/// [SliverAnimatedPaintExtent] allows for smoothly animating maxPaintExtent changes
class SliverAnimatedPaintExtent extends StatefulWidget {
/// The duration that the animation will take
final Duration duration;
/// The curve for the animation
final Curve curve;
/// The child widget that will be rendered
final Widget child;
const SliverAnimatedPaintExtent({
Key? key,
required this.duration,
required this.child,
this.curve = Curves.linear,
}) : super(key: key);
@override
State<SliverAnimatedPaintExtent> createState() =>
_SliverAnimatedPaintExtentState();
}
class _SliverAnimatedPaintExtentState extends State<SliverAnimatedPaintExtent>
with SingleTickerProviderStateMixin {
late AnimationController _controller;
@override
void initState() {
_controller = AnimationController(vsync: this);
super.initState();
}
@override
void dispose() {
_controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return _SliverAnimatedPaintExtent(
controller: _controller,
duration: widget.duration,
curve: widget.curve,
child: widget.child,
);
}
}
class _SliverAnimatedPaintExtent extends SingleChildRenderObjectWidget {
/// The controller in charge of the animation
final AnimationController controller;
/// The duration that the animation will take
final Duration duration;
/// The curve for the animation
final Curve curve;
const _SliverAnimatedPaintExtent({
Key? key,
required this.controller,
required this.duration,
required this.curve,
required Widget child,
}) : super(key: key, child: child);
@override
RenderSliverAnimatedPaintExtent createRenderObject(BuildContext context) {
return RenderSliverAnimatedPaintExtent()
..duration = duration
..controller = controller
..curve = curve;
}
@override
void updateRenderObject(BuildContext context,
covariant RenderSliverAnimatedPaintExtent renderObject) {
renderObject
..duration = duration
..controller = controller
..curve = curve;
}
}