import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'controller.dart';

class SplashPage extends GetView<SplashController> {
  const SplashPage({super.key});

  @override
  Widget build(BuildContext context) {
    // TODO:
    return const ImageAnimation();
  }
}

class ImageAnimation extends StatefulWidget {
  const ImageAnimation({super.key});

  @override
  State<ImageAnimation> createState() => _ImageAnimationState();
}

class _ImageAnimationState extends State<ImageAnimation>
    with SingleTickerProviderStateMixin {
  late AnimationController _controller;
  late Animation<double> _animation;

  @override
  void initState() {
    super.initState();

    // 创建动画控制器
    _controller = AnimationController(
      duration: const Duration(milliseconds: 4200),
      vsync: this,
    );

    // 创建动画
    _animation = Tween<double>(begin: 0, end: 1).animate(_controller);

    // 启动动画
    _controller.forward();

    _controller.addStatusListener((status) {
      if (status == AnimationStatus.completed) {
        // 动画结束
        Get.find<SplashController>().onRouteTo();
      }
    });
  }

  @override
  void dispose() {
    // 销毁动画控制器
    _controller.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Theme.of(context).primaryColor,
      body: Center(
        child: AnimatedBuilder(
          animation: _animation,
          builder: (BuildContext context, Widget? child) {
            return Opacity(
              opacity: _animation.value,
              child: Container(
                alignment: Alignment.center,
                // width: 200,
                height: 200,
                padding: const EdgeInsets.only(right: 80),
                child: Image.asset(
                  'assets/images/vinno_logo.png',
                  fit: BoxFit.fitHeight,
                ),
              ),
            );
          },
        ),
      ),
    );
  }
}
