import 'dart:async'; import 'dart:io'; import 'package:location/location.dart'; import 'Utils/utils.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:shared_preferences/shared_preferences.dart'; import 'Utils/keys.dart'; import 'package:http/http.dart'; import 'Pages/home_page.dart'; import 'Pages/login_page.dart'; import 'Pages/unit_list.dart'; import 'Pages/unit_details.dart'; Client http = Client(); SecurityContext clientContext = SecurityContext(); Util util = Util(); var prefs; Location location = Location(); StreamSubscription? locationStream; LocationData? currentPosisiton; RouteObserver routeObserver = RouteObserver(); registerCert()async{ ByteData bytes = await rootBundle.load('lib/cert/isrgrootx1.pem'); clientContext = SecurityContext() ..setTrustedCertificatesBytes(bytes.buffer.asUint8List()); } Future preLoad() async{ prefs = await SharedPreferences.getInstance(); await prefs?.setString(Keys.hostAddress, "https://tbg.thamringroup.web.id/ords/tbs/unit/v1"); await prefs?.setString(Keys.restTokenAddress, "https://tbg.thamringroup.web.id/ords/tbs/oauth/token"); await registerCert(); } void main()async{ WidgetsFlutterBinding.ensureInitialized(); await preLoad(); SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]) .then((_) { runApp(const MyApp()); }); } class MyApp extends StatelessWidget { const MyApp({Key? key}) : super(key: key); @override Widget build(BuildContext context) { return MaterialApp( navigatorObservers: [routeObserver], title: 'Internal Unit Stocks', debugShowCheckedModeBanner: false, theme: ThemeData( primarySwatch: Colors.blue, ), home: (prefs.getBool(Keys.loggedIn)??false)?const HomePage():const LoginPage(), routes: { '/home': (context) => const HomePage(), '/units' : (context) => new UnitsPage(), '/login' :(context) => const LoginPage(), }, ); } }