import 'package:e_commerce_training/res/R.dart';
import 'package:e_commerce_training/src/page/authentication/authentication.dart';
import 'package:flutter/material.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';
import 'page/splash/splash_page.dart';

class App extends StatefulWidget {
  @override
  _AppState createState() => _AppState();
}

class _AppState extends State<App> {
  late AuthenticationCubit _authenticationCubit;

  @override
  void initState() {
    _authenticationCubit = AuthenticationCubit();
    Future.delayed(Duration(seconds: 3), () {
      _authenticationCubit.openApp();
    });
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return ScreenUtilInit(
        designSize: Size(375, 812),
        builder: () => RefreshConfiguration(
              headerBuilder: () => WaterDropMaterialHeader(),
              // Configure the default header indicator. If you have the same header indicator for each page, you need to set this
              footerBuilder: () => ClassicFooter(
                loadStyle: LoadStyle.HideAlways,
              ),
              child: MaterialApp(
                title: "WeOne",
                theme: ThemeData(
                    primaryColor: R.color.accentColor,
                    accentColor: R.color.accentColor,
                    brightness: Brightness.light,
                    backgroundColor: R.color.white,
                    scaffoldBackgroundColor: R.color.white,
                    dialogBackgroundColor: R.color.white),
                localizationsDelegates: context.localizationDelegates,
                supportedLocales: context.supportedLocales,
                locale: context.locale,
                debugShowCheckedModeBanner: false,
                home: BlocProvider<AuthenticationCubit>(
                  child: BlocBuilder<AuthenticationCubit, AuthenticationState>(
                    builder: (context, state) {
                      return SplashPage();
                    },
                  ),
                  create: (context) => _authenticationCubit,
                ),
              ),
            ));
  }
}
