import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:unitstocks/Util/Prefs.dart';
import 'package:unitstocks/login_page.dart';
import 'home_page.dart';
import 'stocking.dart';
import 'unit_details.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:location/location.dart';
import 'Util/Util.dart';

SharedPreferences prefs;
Location location = Location();
StreamSubscription locationStream;
LocationData currentPosisiton;
Util util = new Util();
void main() async{
  WidgetsFlutterBinding.ensureInitialized();
  prefs = await SharedPreferences.getInstance();
  location.changeSettings(accuracy: LocationAccuracy.high);
  SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp])
      .then((_) {
    runApp(new MyApp());
  });
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Unit Stock',
      theme: ThemeData(
        pageTransitionsTheme: PageTransitionsTheme(
            builders: {
              TargetPlatform.iOS: CupertinoPageTransitionsBuilder(),
            }
        ),
        primarySwatch: Colors.indigo,
      ),
      debugShowCheckedModeBanner: false,

      home: (prefs.getBool(keyClass.logged_in)??false)?HomePage(title:'Home Page'):LoginPage(),
      routes: {
        '/home': (context) => new HomePage(title:'Home Page'),
        '/stocking' : (context) => new Stocking(),
        '/unitdetails' : (context) => new UnitDetails(),
        '/login' :(context) => new LoginPage(),
      },
    );
  }
}

