1
+ import 'package:flutter/material.dart' ;
2
+
3
+ class AnimatedTouchBubblePart extends StatefulWidget {
4
+ AnimatedTouchBubblePart ({this .dragging, this .size});
5
+
6
+ final bool dragging;
7
+ final double size;
8
+
9
+ @override
10
+ _AnimatedTouchBubblePartState createState () => _AnimatedTouchBubblePartState ();
11
+ }
12
+
13
+ class _AnimatedTouchBubblePartState extends State <AnimatedTouchBubblePart > with SingleTickerProviderStateMixin {
14
+ AnimationController _controller;
15
+ Animation <Color > _colorAnimation;
16
+ Animation <double > _sizeAnimation;
17
+
18
+ @override
19
+ void didChangeDependencies () {
20
+ _controller = new AnimationController (
21
+ duration: const Duration (milliseconds: 1000 ),
22
+ vsync: this ,
23
+ );
24
+
25
+ _sizeAnimation = Tween <double >(
26
+ begin: 0.5 ,
27
+ end: 1.0
28
+ ).animate (_controller);
29
+
30
+ _colorAnimation = ColorTween (
31
+ begin: Theme .of (context).accentColor.withOpacity (0.5 ),
32
+ end: Theme .of (context).accentColor.withOpacity (0.0 )
33
+ ).animate (
34
+ CurvedAnimation (
35
+ parent: _controller,
36
+ curve: Interval (0.5 , 1.0 )
37
+ )
38
+ );
39
+
40
+ _controller.repeat ();
41
+ super .didChangeDependencies ();
42
+ }
43
+
44
+ @override
45
+ void dispose () {
46
+ _controller.dispose ();
47
+ super .dispose ();
48
+ }
49
+
50
+ @override
51
+ Widget build (BuildContext context) {
52
+ return Stack (
53
+ children: [
54
+ Center (
55
+ child: Container (
56
+ width: widget.dragging ? widget.size : widget.size / 2 ,
57
+ height: widget.dragging ? widget.size : widget.size / 2 ,
58
+ decoration: BoxDecoration (
59
+ color: Theme .of (context).accentColor.withOpacity (0.5 ),
60
+ borderRadius: widget.dragging ? BorderRadius .circular (widget.size) : BorderRadius .circular (widget.size / 4 )
61
+ )
62
+ )
63
+ ),
64
+ AnimatedBuilder (
65
+ builder: (BuildContext context, Widget child) {
66
+ return Center (
67
+ child: Container (
68
+ width: widget.dragging ? 0 : widget.size * _sizeAnimation.value,
69
+ height: widget.dragging ? 0 : widget.size * _sizeAnimation.value,
70
+ decoration: BoxDecoration (
71
+ border: Border .all (
72
+ color: _colorAnimation.value,
73
+ width: widget.size / 20
74
+ ),
75
+ borderRadius: widget.dragging ? BorderRadius .zero : BorderRadius .circular (widget.size * _sizeAnimation.value / 2 )
76
+ )
77
+ )
78
+ );
79
+ },
80
+ animation: _controller
81
+ )
82
+ ],
83
+ );
84
+ }
85
+ }
0 commit comments