
import 'package:flutter_redux/flutter_redux.dart';
import 'package:flutter/material.dart';
import 'package:satu/core/models/auth/auth_response.dart';
import 'package:satu/core/redux/actions/user_actions.dart';
import 'package:satu/core/redux/state/user_state.dart';
import 'package:satu/core/redux/store.dart';
import 'package:satu/core/services/api_service.dart';
import 'package:satu/core/services/navigator_service.dart';
import 'package:satu/core/utils/locator.dart';
import 'package:satu/routes/route_names.dart';


class StartUpView extends StatefulWidget {
  @override
  _StartUpViewState createState() => _StartUpViewState();
}

class _StartUpViewState extends State<StartUpView> {
  final NavigatorService _navigation = locator<NavigatorService>();
  final ApiService _api = locator<ApiService>();

  @override
  void initState() {
    super.initState();
    // Redux.store.dispatch(checkUserAction);
    redirect();
  }

  @override
  Widget build(BuildContext context) {
    return StoreConnector<AppState, UserState>(
        converter: (store) => store.state.userState!,
        builder: (context, userState) {
          return Scaffold(
              body: Center(
            child: Column(
              mainAxisSize: MainAxisSize.min,
              children: <Widget>[
                SizedBox(
                  width: 500,
                  height: 200,
                  child: Image.asset('assets/images/icon_large.png'),
                ),
                CircularProgressIndicator(
                  strokeWidth: 3,
                  valueColor: AlwaysStoppedAnimation(
                    Colors.yellow[300],
                  ),
                )
              ],
            ),
          ));
        });
  }

  void redirect() async {
    await Future.delayed(Duration(milliseconds: 100));
    Redux.store!.dispatch(auth);
  }
}
