flutter app untuk unitstock
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

84 line
2.7 KiB

  1. import 'dart:async';
  2. import 'dart:io';
  3. import 'package:flutter/material.dart';
  4. import 'package:flutter/services.dart';
  5. import 'package:http/http.dart';
  6. import 'package:unitstocks/Util/Prefs.dart';
  7. import 'package:unitstocks/login_page.dart';
  8. import 'home_page.dart';
  9. import 'stocking.dart';
  10. import 'unit_details.dart';
  11. import 'package:shared_preferences/shared_preferences.dart';
  12. import 'package:location/location.dart';
  13. import 'Util/Util.dart';
  14. import 'package:flutter_logs/flutter_logs.dart';
  15. SharedPreferences prefs;
  16. Location location = Location();
  17. StreamSubscription locationStream;
  18. LocationData currentPosisiton;
  19. Util util = new Util();
  20. Client http = new Client();
  21. SecurityContext clientContext;
  22. registerCert()async{
  23. ByteData bytes = await rootBundle.load('cert/isrgrootx1.pem');
  24. clientContext = new SecurityContext()
  25. ..setTrustedCertificatesBytes(bytes.buffer.asUint8List());
  26. }
  27. void main() async{
  28. WidgetsFlutterBinding.ensureInitialized();
  29. prefs = await SharedPreferences.getInstance();
  30. await registerCert();
  31. if( prefs.getString(keyClass.hostAddress) ==null)await prefs.setString(keyClass.hostAddress, "https://tbg.thamringroup.web.id/ords/tbs/unit/v1");
  32. await prefs.setString(keyClass.restTokenAddress, "https://tbg.thamringroup.web.id/ords/tbs/oauth/token");
  33. await FlutterLogs.initLogs(
  34. logLevelsEnabled: [
  35. LogLevel.INFO,
  36. LogLevel.WARNING,
  37. LogLevel.ERROR,
  38. LogLevel.SEVERE
  39. ],
  40. timeStampFormat: TimeStampFormat.TIME_FORMAT_READABLE,
  41. directoryStructure: DirectoryStructure.FOR_DATE,
  42. logTypesEnabled: ["device","network","errors"],
  43. logFileExtension: LogFileExtension.LOG,
  44. logsWriteDirectoryName: "MyLogs",
  45. logsExportDirectoryName: "MyLogs/Exported",
  46. debugFileOperations: true,
  47. isDebuggable: true);
  48. SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp])
  49. .then((_) {
  50. runApp(new MyApp());
  51. });
  52. }
  53. class MyApp extends StatelessWidget {
  54. @override
  55. Widget build(BuildContext context) {
  56. return MaterialApp(
  57. title: 'Unit Stock',
  58. theme: ThemeData(
  59. pageTransitionsTheme: PageTransitionsTheme(
  60. builders: {
  61. TargetPlatform.iOS: CupertinoPageTransitionsBuilder(),
  62. }
  63. ),
  64. primarySwatch: Colors.indigo,
  65. ),
  66. debugShowCheckedModeBanner: false,
  67. home: (prefs.getBool(keyClass.logged_in)??false)?HomePage(title:'Home Page'):LoginPage(),
  68. routes: {
  69. '/home': (context) => new HomePage(title:'Home Page'),
  70. '/stocking' : (context) => new Stocking(),
  71. '/unitdetails' : (context) => new UnitDetails(),
  72. '/login' :(context) => new LoginPage(),
  73. },
  74. );
  75. }
  76. }