import 'dart:convert';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:generp/services/api_calling.dart';
import 'package:provider/provider.dart';

import '../Notifiers/splashVersionNotifier.dart';

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

  @override
  State<Splash> createState() => _SplashState();
}

class _SplashState extends State<Splash> {


  late Image splashImage;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    splashImage = Image.asset("assets/images/ic_splash.jpg");
    final spalshProvider = Provider.of<SplashVersionNotifier>(context,listen: false);
    spalshProvider.initPackageInfo();
    spalshProvider.handleVersionCheck(context);

  }

  @override
  void didChangeDependencies() {
    // TODO: implement didChangeDependencies
    super.didChangeDependencies();
    precacheImage(splashImage.image, context);
  }


  @override
  Widget build(BuildContext context) {

    return Scaffold(
      body:  Consumer<SplashVersionNotifier>(builder: (context, value, child) {

        return Container(
            alignment: Alignment.center,
            child: Container(
              alignment: Alignment.center,
              height: 300,
              width: 300,
              child: splashImage,
            ));
        }
      ),
    );
  }
}
