张延森 3 years ago
parent
commit
0e6978b923
4 changed files with 87 additions and 19 deletions
  1. 37
    19
      lib/main.dart
  2. 12
    0
      lib/pages/home.dart
  3. 22
    0
      lib/pages/launch.dart
  4. 16
    0
      lib/utils/timer.dart

+ 37
- 19
lib/main.dart View File

@@ -1,6 +1,7 @@
1 1
 import 'dart:async';
2 2
 
3 3
 import 'package:farmer_client/models/Store.dart';
4
+import 'package:farmer_client/pages/home.dart';
4 5
 import 'package:farmer_client/pages/login/login.dart';
5 6
 import 'package:flutter/material.dart';
6 7
 import 'package:get/get.dart';
@@ -11,9 +12,10 @@ import 'widgets/OrderListCard.dart';
11 12
 
12 13
 
13 14
 void main() async {
14
-  Store().init();
15 15
   await GetStorage.init();
16
-  runApp(const MyApp());
16
+  Store().init();
17
+
18
+  runApp(MyApp());
17 19
 }
18 20
 
19 21
 class MyApp extends StatelessWidget {
@@ -22,24 +24,40 @@ class MyApp extends StatelessWidget {
22 24
   // This widget is the root of your application.
23 25
   @override
24 26
   Widget build(BuildContext context) {
25
-
26
-    return MaterialApp(
27
-      title: 'Flutter Demo',
28
-      theme: ThemeData(
29
-        // This is the theme of your application.
30
-        //
31
-        // Try running your application with "flutter run". You'll see the
32
-        // application has a blue toolbar. Then, without quitting the app, try
33
-        // changing the primarySwatch below to Colors.green and then invoke
34
-        // "hot reload" (press "r" in the console where you ran "flutter run",
35
-        // or simply save your changes to "hot reload" in a Flutter IDE).
36
-        // Notice that the counter didn't reset back to zero; the application
37
-        // is not restarted.
38
-        primarySwatch: Colors.blue,
39
-      ),
40
-      home:  const MyHomePage(title: 'Flutter Demo Home Page'),
41
-
27
+    GetStorage box = GetStorage();
28
+
29
+    return ScreenUtilInit(
30
+      designSize: const Size(375, 812),
31
+      minTextAdapt: true,
32
+      splitScreenMode: true,
33
+      builder: (_) {
34
+        return GetMaterialApp(
35
+          initialRoute: '/home',
36
+          defaultTransition: Transition.native,
37
+          getPages: [
38
+            GetPage(name: '/home', page: () => box.hasData('token') ? Home() : MyRouteLogin()),
39
+          ],
40
+        );
41
+      },
42 42
     );
43
+
44
+    // return MaterialApp(
45
+    //   title: 'Flutter Demo',
46
+    //   theme: ThemeData(
47
+    //     // This is the theme of your application.
48
+    //     //
49
+    //     // Try running your application with "flutter run". You'll see the
50
+    //     // application has a blue toolbar. Then, without quitting the app, try
51
+    //     // changing the primarySwatch below to Colors.green and then invoke
52
+    //     // "hot reload" (press "r" in the console where you ran "flutter run",
53
+    //     // or simply save your changes to "hot reload" in a Flutter IDE).
54
+    //     // Notice that the counter didn't reset back to zero; the application
55
+    //     // is not restarted.
56
+    //     primarySwatch: Colors.blue,
57
+    //   ),
58
+    //   home:  const MyHomePage(title: 'Flutter Demo Home Page'),
59
+    //
60
+    // );
43 61
   }
44 62
 }
45 63
 

+ 12
- 0
lib/pages/home.dart View File

@@ -0,0 +1,12 @@
1
+
2
+import 'package:farmer_client/models/User.dart';
3
+import 'package:flutter/widgets.dart';
4
+import 'package:get/get.dart';
5
+
6
+class Home extends GetView<User> {
7
+  @override
8
+  Widget build(BuildContext context) {
9
+    return Text("首页示例");
10
+  }
11
+
12
+}

+ 22
- 0
lib/pages/launch.dart View File

@@ -0,0 +1,22 @@
1
+
2
+
3
+import 'package:flutter/widgets.dart';
4
+
5
+class Launch extends StatefulWidget {
6
+  @override
7
+  State<StatefulWidget> createState() => LaunchState();
8
+}
9
+
10
+class LaunchState extends State<Launch> {
11
+
12
+  // 默认 3s
13
+  int _countdown = 3;
14
+
15
+  @override
16
+  Widget build(BuildContext context) {
17
+    // TODO: implement build
18
+    throw UnimplementedError();
19
+  }
20
+
21
+}
22
+

+ 16
- 0
lib/utils/timer.dart View File

@@ -0,0 +1,16 @@
1
+
2
+import 'dart:async';
3
+
4
+Timer setInterval(void Function (Timer) f, int milliseconds) {
5
+  var duration = Duration(milliseconds: milliseconds);
6
+  return Timer.periodic(duration, f);
7
+}
8
+
9
+//
10
+// Timer setTimeout(void Function () f, int milliseconds) {
11
+//   if
12
+//
13
+//
14
+//   var duration = Duration(milliseconds: milliseconds);
15
+//   return Timer(duration, f);
16
+// }