animated_touch_bubble_part.dart 2.7 KB

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