loading.dart 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import 'dart:math';
  2. import 'package:fast/utils/size_fit.dart';
  3. import 'package:flutter/material.dart';
  4. class Loading extends StatefulWidget {
  5. bool showBg = true;
  6. Loading({Key? key, bool? showBackground}) : super(key: key) {
  7. if (showBackground != null) {
  8. showBg = showBackground;
  9. }
  10. }
  11. @override
  12. State<Loading> createState() => _LoadingState();
  13. }
  14. class _LoadingState extends State<Loading> with SingleTickerProviderStateMixin {
  15. late AnimationController controller;
  16. late Animation animation;
  17. @override
  18. void initState() {
  19. controller = AnimationController(
  20. vsync: this, duration: const Duration(milliseconds: 1200));
  21. animation = Tween(begin: 0.0, end: 2 * pi).animate(controller);
  22. controller.addListener(() {
  23. setState(() {});
  24. });
  25. controller.repeat();
  26. super.initState();
  27. }
  28. @override
  29. void dispose() {
  30. controller.dispose();
  31. super.dispose();
  32. }
  33. @override
  34. Widget build(BuildContext context) {
  35. SizeFit.initialize(context);
  36. return SizedBox(
  37. width: 144.px,
  38. height: 150.px,
  39. child: Container(
  40. alignment: Alignment.center,
  41. child: Container(
  42. width: 144.px,
  43. height: 150.px,
  44. alignment: Alignment.center,
  45. child: Transform.rotate(
  46. angle: animation.value,
  47. child: Image.asset(
  48. 'assets/images/loading.png',
  49. width: 80.px,
  50. height: 80.px,
  51. ),
  52. ),
  53. decoration: widget.showBg
  54. ? BoxDecoration(
  55. color: const Color(0xFF313F52),
  56. borderRadius: BorderRadius.all(Radius.circular(32.px)),
  57. boxShadow: [
  58. BoxShadow(
  59. color: const Color(0xFF000D1F),
  60. blurRadius: 24.px,
  61. offset: Offset(0, 12.px))
  62. ])
  63. : const BoxDecoration(color: Colors.transparent),
  64. ),
  65. ),
  66. );
  67. }
  68. }