import 'package:farmer_client/pages/splash/widgets/countdown.dart';
import 'package:get/get.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter/material.dart';
import 'package:get_storage/get_storage.dart';

class SplashScreen extends StatefulWidget {
  const SplashScreen({Key? key}) : super(key: key);

  @override
  State<SplashScreen> createState() => _SplashScreen();
}

class _SplashScreen extends State<SplashScreen> {
  GetStorage box = GetStorage();
  handleOnFinish() {
    bool isLogin = box.hasData('token');
    if (isLogin) {
      Get.offNamed('/');
    } else {
      Get.offNamed('/login');
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        body: Container(
      decoration: const BoxDecoration(
        image: DecorationImage(
            image: AssetImage("images/splash.png"),
            fit: BoxFit.cover,
            alignment: Alignment.topCenter),
      ),
      child: Stack(
        children: [
          Positioned(
            right: 15.w,
            top: 50.h,
            child: countdown(3, handleOnFinish),
          ),
          Positioned(
            bottom: 0,
            child: Container(
              width: 375.w,
              height: 60.w,
              child: Center(
                child: Image.asset(
                  'images/logo.png',
                  width: 218.w,
                  height: 50.w,
                ),
              ),
            ),
          ),
        ],
      ),
    ));
  }
}