import 'dart:async';

import 'package:driverapp/app-icons/driver_app_icons.dart';
import 'package:driverapp/core/viewModels/project_view_model.dart';
import 'package:driverapp/root_page.dart';
import 'package:driverapp/widgets/others/app_scaffold_widget.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

class SplashScreenPage extends StatefulWidget {
  @override
  _SplashScreenPageState createState() => _SplashScreenPageState();
}

class _SplashScreenPageState extends State<SplashScreenPage> {
  startTime() async {
    var _duration = new Duration(seconds: 2);
    return new Timer(_duration, navigationPage);
  }

  @override
  void initState() {
    super.initState();
    startTime();
  }

  @override
  Widget build(BuildContext context) {
    ProjectViewModel projectViewModel = Provider.of(context);

    return AppScaffold(
      isShowAppBar: false,
      appBarColor: Color(0xff30B7B9),
      body: SingleChildScrollView(
        child: Center(
          child: Column(
//            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: <Widget>[
              FractionallySizedBox(
                widthFactor: 0.80,
                child: Column(
                  children: <Widget>[
                    SizedBox(
                      height: 200,
                    ),
                    Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: <Widget>[
                        Container(
                          child: Icon(
                            DriverApp.logo,
                            size: 110,
                            color: Colors.white,
                          ),
                          margin: EdgeInsets.only(
                              right: projectViewModel.isArabic
                                  ? 0
                                  : MediaQuery.of(context).size.width * 0.15,
                              left: !projectViewModel.isArabic
                                  ? 0
                                  : MediaQuery.of(context).size.width * 0.15),
                        ),
                      ],
                    ),
                    SizedBox(
                      height: 20,
                    ),
                    Column(
                      children: <Widget>[
                        Text(
                          "Driver",
                          style: TextStyle(
                              fontSize: 70,
                              fontWeight: FontWeight.bold,
                              color: Colors.white),
                        ),
                        Text(
                          "Delivery",
                          style: TextStyle(
                              fontSize: 50,
                              letterSpacing: 1,
                              color: Colors.white),
                        ),
                        Text(
                          "APP",
                          style: TextStyle(
                              fontSize: 53,
                              letterSpacing: 53,
                              color: Colors.white,
                              fontWeight: FontWeight.w400),
                        ),
                      ],
                    ),
                    SizedBox(
                      height: 280,
                    )
                  ],
                ),
              ),
              Center(
                child: FractionallySizedBox(
                  widthFactor: 0.80,
                  child: Column(
                    children: <Widget>[
                      Column(
                        mainAxisAlignment: MainAxisAlignment.end,
                        crossAxisAlignment: CrossAxisAlignment.center,
                        children: <Widget>[
                          Padding(
                            padding: const EdgeInsets.symmetric(horizontal: 0),
                            child: Row(
                              mainAxisAlignment: MainAxisAlignment.end,
                              children: <Widget>[
                                Expanded(
                                  child: Center(
                                    child: Text(
                                      "Powered by Cloud Solutions",
                                      style: TextStyle(
                                          fontSize: 13, color: Colors.white),
                                    ),
                                  ),
                                ),
                                SizedBox(
                                  height: 10,
                                )
                              ],
                            ),
                          ),
                        ],
                      ),
                    ],
                  ),
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }

  void navigationPage() {
    Navigator.pushReplacement(
      context,
      MaterialPageRoute(
        builder: (context) => RootPage(),
      ),
    );
  }
}
