import 'dart:async';
import 'package:diplomaticquarterapp/pages/landing/landing_page.dart';
import 'package:diplomaticquarterapp/uitl/app_shared_preferences.dart';
import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart';
import 'package:diplomaticquarterapp/widgets/transitions/fade_page.dart';
import 'package:firebase_analytics/observer.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:provider/provider.dart';

import 'analytics/google-analytics.dart';
import 'config/shared_pref_kay.dart';
import 'config/size_config.dart';
import 'core/service/AuthenticatedUserObject.dart';
import 'core/service/privilege_service.dart';
import 'core/viewModels/project_view_model.dart';
import 'locator.dart';
import 'models/Authentication/authenticated_user.dart';
import 'widgets/transitions/slide_up_page.dart';

AppSharedPreferences sharedPref = new AppSharedPreferences();
AuthenticatedUserObject authenticatedUserObject =
    locator<AuthenticatedUserObject>();

class SplashScreen extends StatefulWidget {
  @override
  _SplashScreenState createState() => _SplashScreenState();
}

class _SplashScreenState extends State<SplashScreen> {
  PrivilegeService _privilegeService = locator<PrivilegeService>();
  @override
  void initState() {
    super.initState();
    Timer(
      Duration(seconds: 1, milliseconds: 500),
      () {
        loadPrivilege().then((value) {
          Navigator.of(context).pushReplacement(
            MaterialPageRoute(
              builder: (BuildContext context) => LandingPage(),
            ),
          );
        });
      },
    );
  }

  /// load the Privilege from service
  Future loadPrivilege() async {
    await _privilegeService.getPrivilege();
    Provider.of<ProjectViewModel>(context, listen: false)
        .setPrivilegeModelList(privilege: _privilegeService.privilegeModelList);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.white,
      body: Image.asset(
        'assets/images/powerd-by.jpg',
        fit: BoxFit.fitWidth,
        width: MediaQuery.of(context).size.width,
      ),
    );
  }
}
