main.dart 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. import 'dart:async';
  2. import 'package:farmer_client/models/Store.dart';
  3. import 'package:farmer_client/pages/home.dart';
  4. import 'package:farmer_client/pages/login/login.dart';
  5. import 'package:farmer_client/widgets/CarsCard.dart';
  6. import 'package:farmer_client/widgets/OrderInfoCard.dart';
  7. import 'package:flutter/material.dart';
  8. import 'package:get/get.dart';
  9. import 'package:get_storage/get_storage.dart';
  10. import 'package:flutter_screenutil/flutter_screenutil.dart';
  11. import 'widgets/OrderListCard.dart';
  12. void main() async {
  13. await GetStorage.init();
  14. Store().init();
  15. runApp(MyApp());
  16. }
  17. class MyApp extends StatelessWidget {
  18. const MyApp({Key? key}) : super(key: key);
  19. // This widget is the root of your application.
  20. @override
  21. Widget build(BuildContext context) {
  22. GetStorage box = GetStorage();
  23. return ScreenUtilInit(
  24. designSize: const Size(375, 812),
  25. minTextAdapt: true,
  26. splitScreenMode: true,
  27. builder: (_) {
  28. return GetMaterialApp(
  29. initialRoute: '/home',
  30. defaultTransition: Transition.native,
  31. getPages: [
  32. // GetPage(name: '/home', page: () => OrderPage() ),
  33. GetPage(name: '/home', page: () => box.hasData('token') ? Home() : MyRouteLogin()),
  34. ],
  35. );
  36. },
  37. );
  38. // return MaterialApp(
  39. // title: 'Flutter Demo',
  40. // theme: ThemeData(
  41. // // This is the theme of your application.
  42. // //
  43. // // Try running your application with "flutter run". You'll see the
  44. // // application has a blue toolbar. Then, without quitting the app, try
  45. // // changing the primarySwatch below to Colors.green and then invoke
  46. // // "hot reload" (press "r" in the console where you ran "flutter run",
  47. // // or simply save your changes to "hot reload" in a Flutter IDE).
  48. // // Notice that the counter didn't reset back to zero; the application
  49. // // is not restarted.
  50. // primarySwatch: Colors.blue,
  51. // ),
  52. // home: const MyHomePage(title: 'Flutter Demo Home Page'),
  53. //
  54. // );
  55. }
  56. }
  57. class MyHomePage extends StatefulWidget {
  58. const MyHomePage({Key? key,}) : super(key: key);
  59. // This widget is the home page of your application. It is stateful, meaning
  60. // that it has a State object (defined below) that contains fields that affect
  61. // how it looks.
  62. // This class is the configuration for the state. It holds the values (in this
  63. // case the title) provided by the parent (in this case the App widget) and
  64. // used by the build method of the State. Fields in a Widget subclass are
  65. // always marked "final".
  66. // final String title;
  67. @override
  68. State<MyHomePage> createState() => _MyHomePageState();
  69. }
  70. class _MyHomePageState extends State<MyHomePage> {
  71. int _counter = 0;
  72. @override
  73. Widget build(BuildContext context) {
  74. // var find = Get.find(tag: 'user');
  75. // This method is rerun every time setState is called, for instance as done
  76. // by the _incrementCounter method above.
  77. //
  78. // The Flutter framework has been optimized to make rerunning build methods
  79. // fast, so that you can just rebuild anything that needs updating rather
  80. // than having to individually change instances of widgets.
  81. return Scaffold(
  82. appBar: AppBar(
  83. backgroundColor: Colors.amber,
  84. // Here we take the value from the MyHomePage object that was created by
  85. // the App.build method, and use it to set our appbar title.
  86. title: Text('widget.title'),
  87. ),
  88. body: Center(
  89. // Center is a layout widget. It takes a single child and positions it
  90. // in the middle of the parent.
  91. child: Column(
  92. // Column is also a layout widget. It takes a list of children and
  93. // arranges them vertically. By default, it sizes itself to fit its
  94. // children horizontally, and tries to be as tall as its parent.
  95. //
  96. // Invoke "debug painting" (press "p" in the console, choose the
  97. // "Toggle Debug Paint" action from the Flutter Inspector in Android
  98. // Studio, or the "Toggle Debug Paint" command in Visual Studio Code)
  99. // to see the wireframe for each widget.
  100. //
  101. // Column has various properties to control how it sizes itself and
  102. // how it positions its children. Here we use mainAxisAlignment to
  103. // center the children vertically; the main axis here is the vertical
  104. // axis because Columns are vertical (the cross axis would be
  105. // horizontal).
  106. mainAxisAlignment: MainAxisAlignment.center,
  107. children: <Widget>[
  108. // Text(
  109. // '$_counter',
  110. // style: Theme.of(context).textTheme.headline4,
  111. // ),
  112. // DefaultButton(
  113. // margin: EdgeInsets.fromLTRB(0, 30.0, 0, 0), //可选配置,自定义控件中有默认配置
  114. // text: "登陆",
  115. // width: 120.0,
  116. // height: 50.0,
  117. // fontSize: 20.0,
  118. // backColor: Color(0xffff703b),
  119. // color: Colors.white,
  120. // onPressed: () {
  121. // Navigator.push(
  122. // context,
  123. // MaterialPageRoute(builder: (context) {
  124. // return MyRouteLogin();
  125. // }),
  126. // );
  127. // },
  128. // ),
  129. CarsCard(),
  130. // Search()
  131. // OrderListCard()
  132. ],
  133. ),
  134. ),
  135. // This trailing comma makes auto-formatting nicer for build methods.
  136. );
  137. }
  138. }