loadding.dart 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. import 'package:fis_ui/index.dart';
  2. import 'package:flutter/widgets.dart';
  3. class SpinKitChasingDots extends StatefulWidget implements FWidget {
  4. const SpinKitChasingDots({
  5. Key? key,
  6. this.color,
  7. this.size = 50.0,
  8. this.itemBuilder,
  9. this.duration = const Duration(milliseconds: 2000),
  10. }) : assert(
  11. !(itemBuilder is IndexedWidgetBuilder && color is Color) &&
  12. !(itemBuilder == null && color == null),
  13. 'You should specify either a itemBuilder or a color'),
  14. super(key: key);
  15. final Color? color;
  16. final double size;
  17. final IndexedWidgetBuilder? itemBuilder;
  18. final Duration duration;
  19. @override
  20. _SpinKitChasingDotsState createState() => _SpinKitChasingDotsState();
  21. }
  22. class _SpinKitChasingDotsState extends State<SpinKitChasingDots>
  23. with TickerProviderStateMixin {
  24. late AnimationController _scaleCtrl;
  25. late AnimationController _rotateCtrl;
  26. late Animation<double> _scale;
  27. late Animation<double> _rotate;
  28. @override
  29. void initState() {
  30. super.initState();
  31. _scaleCtrl = AnimationController(vsync: this, duration: widget.duration)
  32. ..addListener(() => setState(() {}))
  33. ..repeat(reverse: true);
  34. _scale = Tween(begin: -1.0, end: 1.0)
  35. .animate(CurvedAnimation(parent: _scaleCtrl, curve: Curves.easeInOut));
  36. _rotateCtrl = AnimationController(vsync: this, duration: widget.duration)
  37. ..addListener(() => setState(() {}))
  38. ..repeat();
  39. _rotate = Tween(begin: 0.0, end: 360.0)
  40. .animate(CurvedAnimation(parent: _rotateCtrl, curve: Curves.linear));
  41. }
  42. @override
  43. void dispose() {
  44. _scaleCtrl.dispose();
  45. _rotateCtrl.dispose();
  46. super.dispose();
  47. }
  48. @override
  49. FWidget build(BuildContext context) {
  50. return QuickFWidget(
  51. Center(
  52. child: SizedBox.fromSize(
  53. size: Size.square(widget.size),
  54. child: Transform.rotate(
  55. angle: _rotate.value * 0.0174533,
  56. child: Stack(
  57. children: <Widget>[
  58. Positioned(
  59. top: 0.0, child: _circle(1.0 - _scale.value.abs(), 0)),
  60. Positioned(bottom: 0.0, child: _circle(_scale.value.abs(), 1)),
  61. ],
  62. ),
  63. ),
  64. ),
  65. ),
  66. );
  67. }
  68. Widget _circle(double scale, int index) {
  69. return Transform.scale(
  70. scale: scale,
  71. child: SizedBox.fromSize(
  72. size: Size.square(widget.size * 0.6),
  73. child: widget.itemBuilder != null
  74. ? widget.itemBuilder!(context, index)
  75. : DecoratedBox(
  76. decoration:
  77. BoxDecoration(shape: BoxShape.circle, color: widget.color)),
  78. ),
  79. );
  80. }
  81. }
  82. class QuickFWidget extends StatelessWidget implements FWidget {
  83. const QuickFWidget(this.child, {Key? key}) : super(key: key);
  84. final Widget child;
  85. @override
  86. Widget build(BuildContext context) => child;
  87. }