view.dart 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import 'package:flutter/material.dart';
  2. import 'package:get/get.dart';
  3. import 'controller.dart';
  4. class SplashPage extends GetView<SplashController> {
  5. const SplashPage({super.key});
  6. @override
  7. Widget build(BuildContext context) {
  8. // TODO:
  9. return const ImageAnimation();
  10. }
  11. }
  12. class ImageAnimation extends StatefulWidget {
  13. const ImageAnimation({super.key});
  14. @override
  15. State<ImageAnimation> createState() => _ImageAnimationState();
  16. }
  17. class _ImageAnimationState extends State<ImageAnimation>
  18. with SingleTickerProviderStateMixin {
  19. late AnimationController _controller;
  20. late Animation<double> _animation;
  21. @override
  22. void initState() {
  23. super.initState();
  24. // 创建动画控制器
  25. _controller = AnimationController(
  26. duration: const Duration(milliseconds: 4200),
  27. vsync: this,
  28. );
  29. // 创建动画
  30. _animation = Tween<double>(begin: 0, end: 1).animate(_controller);
  31. // 启动动画
  32. _controller.forward();
  33. _controller.addStatusListener((status) {
  34. if (status == AnimationStatus.completed) {
  35. // 动画结束
  36. Get.find<SplashController>().onRouteTo();
  37. }
  38. });
  39. }
  40. @override
  41. void dispose() {
  42. // 销毁动画控制器
  43. _controller.dispose();
  44. super.dispose();
  45. }
  46. @override
  47. Widget build(BuildContext context) {
  48. return Scaffold(
  49. backgroundColor: Theme.of(context).primaryColor,
  50. body: Center(
  51. child: AnimatedBuilder(
  52. animation: _animation,
  53. builder: (BuildContext context, Widget? child) {
  54. return Opacity(
  55. opacity: _animation.value,
  56. child: Container(
  57. alignment: Alignment.center,
  58. // width: 200,
  59. height: 200,
  60. padding: const EdgeInsets.only(right: 80),
  61. child: Image.asset(
  62. 'assets/images/vinno_logo.png',
  63. fit: BoxFit.fitHeight,
  64. ),
  65. ),
  66. );
  67. },
  68. ),
  69. ),
  70. );
  71. }
  72. }