李志伟 3 jaren geleden
bovenliggende
commit
a184df1dce

BIN
images/noData.png Bestand weergeven


+ 3
- 3
lib/main.dart Bestand weergeven

@@ -1,8 +1,8 @@
1 1
 import 'package:flutter/material.dart';
2 2
 import 'package:flutter_screenutil/flutter_screenutil.dart';
3 3
 import 'package:get_storage/get_storage.dart';
4
+import 'package:worker_client/theme.dart';
4 5
 import 'models/index.dart';
5
-import '../models/Store.dart';
6 6
 import 'package:get/get.dart';
7 7
 import 'routes/index.dart';
8 8
 
@@ -16,7 +16,6 @@ class MyApp extends StatelessWidget {
16 16
 
17 17
   @override
18 18
   Widget build(BuildContext context) {
19
-    Store().init();
20 19
 
21 20
     return ScreenUtilInit(
22 21
       designSize: const Size(375, 812),
@@ -24,7 +23,8 @@ class MyApp extends StatelessWidget {
24 23
       splitScreenMode: true,
25 24
       builder: (_) {
26 25
         return GetMaterialApp(
27
-          initialRoute: '/splash',
26
+          initialRoute: '/',
27
+          theme: getTheme(),
28 28
           defaultTransition: Transition.native,
29 29
           routingCallback: routingCallback,
30 30
           initialBinding: AppBindings(),

+ 2
- 2
lib/pages/Login/index.dart Bestand weergeven

@@ -115,8 +115,8 @@ class _Login extends State<Login> {
115 115
           child: Column(
116 116
             crossAxisAlignment: CrossAxisAlignment.start,
117 117
             children: [
118
-              Padding(
119
-                padding: EdgeInsets.fromLTRB(0, 20.h, 0, 11.5.h),
118
+              SizedBox(
119
+                height: 44.w,
120 120
                 child: Center(
121 121
                   child: Text(
122 122
                     '登录',

+ 8
- 119
lib/pages/home/index.dart Bestand weergeven

@@ -1,127 +1,16 @@
1
-import 'package:flutter/cupertino.dart';
2 1
 import 'package:flutter/material.dart';
3
-import 'package:get/get.dart';
4
-import 'package:flutter_screenutil/flutter_screenutil.dart';
2
+import 'package:worker_client/widgets/layout/BasicPage.dart';
3
+import './widgets/home/index.dart';
5 4
 
6
-class Home extends StatefulWidget {
7
-  const Home({Key? key}) : super(key: key);
8 5
 
9
-  @override
10
-  _Home createState() => _Home();
11
-}
12
-
13
-class _Home extends State<Home> {
14
-  //下标   当前tab
15
-  int _tabIndex = 0;
16
-
17
-  final List _titles = ['首页', '订单列表', '个人中心'];
18
-  final tabTextStyleSelected = TextStyle(
19
-      color: const Color(0xFF06B03B),
20
-      fontSize: 15.sp,
21
-      fontWeight: FontWeight.bold); //选线卡选中字体颜色
22
-  final tabTextStyleNormal = TextStyle(
23
-      color: const Color(0xFF323232),
24
-      fontSize: 15.sp,
25
-      fontWeight: FontWeight.bold); //选项卡未选中字体颜色
26
-
27
-  TextStyle getTabTextStyle(int curIndex) {
28
-    //设置tabbar 选中和未选中的状态文本
29
-    if (curIndex == _tabIndex) {
30
-      return tabTextStyleSelected;
31
-    }
32
-    return tabTextStyleNormal;
33
-  }
34
-
35
-  // 切换底部选项卡,标题的变化设置
36
-  Text getTabTitle(int curIndex) {
37
-    return Text(_titles[curIndex], style: getTabTextStyle(curIndex));
38
-  }
39
-
40
-  List images = [
41
-    ['images/index/index.png', 'images/index/indexActive.png'],
42
-    ['images/index/job.png', 'images/index/jobActive.png'],
43
-    ['images/index/user.png', 'images/index/userActive.png'],
44
-  ];
45
-  Image getTabIcon(int curIndex) {
46
-    //设置tabbar选中和未选中的状态图标
47
-    if (curIndex == _tabIndex) {
48
-      return Image.asset(
49
-        images[curIndex][1],
50
-        width: 26.w,
51
-        height: 26.w,
52
-      );
53
-    }
54
-    return Image.asset(
55
-      images[curIndex][0],
56
-      width: 26.w,
57
-      height: 26.w,
58
-    );
59
-  }
60
-
61
-  Image getTabImage(path) {
62
-    return Image.asset(path, width: 26.w, height: 26.w);
63
-  }
64
-
65
-  //内容
66
-  var _body = [Text('我是首页'), Text('我是订单列表'), Text('我是个人中心')];
67
-
68
-  Widget tabBar(index) {
69
-    return GestureDetector(
70
-      behavior: HitTestBehavior.opaque,
71
-      onTap: () {
72
-        setState(() {
73
-          _tabIndex = index;
74
-        });
75
-      },
76
-      child: Container(
77
-        width: 125.w,
78
-        height: 65.h,
79
-        child: Column(
80
-          children: [
81
-            getTabIcon(index),
82
-            Padding(
83
-              padding: EdgeInsets.fromLTRB(0, 6.h, 0, 0),
84
-              child: getTabTitle(index),
85
-            )
86
-          ],
87
-        ),
88
-      ),
89
-    );
6
+class Home extends BasicPage {
7
+  Home({Key? key}) : super(key: key) {
8
+    tabIndex = 0;
9
+    naviTitle = '首页';
90 10
   }
91 11
 
92 12
   @override
93
-  Widget build(BuildContext context) {
94
-    return Scaffold(
95
-      appBar: AppBar(
96
-        elevation: 0,
97
-        centerTitle: true,
98
-        backgroundColor: Colors.white,
99
-        title: Text(
100
-          _titles[_tabIndex],
101
-          style: TextStyle(
102
-              color: Colors.black,
103
-              fontSize: 17.sp,
104
-              letterSpacing: 2,
105
-              fontWeight: FontWeight.bold),
106
-        ),
107
-      ),
108
-      body: _body[_tabIndex],
109
-      bottomNavigationBar: Container(
110
-        padding: EdgeInsets.fromLTRB(0, 7.h, 0, 7.h),
111
-        decoration: BoxDecoration(
112
-          color: const Color(0xFFFFFFFF),
113
-          boxShadow: [
114
-            BoxShadow(
115
-              color: const Color(0x14000000),
116
-              offset: Offset(0, -2.w),
117
-              blurRadius: 3.w,
118
-            ),
119
-          ],
120
-        ),
121
-        child: Row(
122
-          children:_titles.asMap().keys.map((index) =>tabBar(index)).toList(),
123
-        ),
124
-      ),
125
-    );
13
+  Widget builder(BuildContext context) {
14
+    return const HomePage();
126 15
   }
127 16
 }

+ 117
- 0
lib/pages/home/widgets/home/index.dart Bestand weergeven

@@ -0,0 +1,117 @@
1
+import 'package:carousel_slider/carousel_slider.dart';
2
+import 'package:flutter/material.dart';
3
+import 'package:flutter_screenutil/flutter_screenutil.dart';
4
+import 'package:get/get.dart';
5
+import 'package:worker_client/pages/home/widgets/home/widgets/headers.dart';
6
+
7
+class HomePage extends StatefulWidget {
8
+  const HomePage({Key? key}) : super(key: key);
9
+
10
+  @override
11
+  State<HomePage> createState() => _HomePageState();
12
+}
13
+
14
+class _HomePageState extends State<HomePage> {
15
+  final List<String> imgList = [
16
+    'https://images.unsplash.com/photo-1520342868574-5fa3804e551c?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=6ff92caffcdd63681a35134a6770ed3b&auto=format&fit=crop&w=1951&q=80',
17
+    'https://images.unsplash.com/photo-1522205408450-add114ad53fe?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=368f45b0888aeb0b7b08e3a1084d3ede&auto=format&fit=crop&w=1950&q=80',
18
+    'https://images.unsplash.com/photo-1519125323398-675f0ddb6308?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=94a1e718d89ca60a6337a6008341ca50&auto=format&fit=crop&w=1950&q=80',
19
+    'https://images.unsplash.com/photo-1523205771623-e0faa4d2813d?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=89719a0d55dd05e2deae4120227e6efc&auto=format&fit=crop&w=1953&q=80',
20
+    'https://images.unsplash.com/photo-1508704019882-f9cf40e475b4?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=8c6e5e3aba713b17aa1fe71ab4f0ae5b&auto=format&fit=crop&w=1352&q=80',
21
+    'https://images.unsplash.com/photo-1519985176271-adb1088fa94c?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=a0c8d632e977f94e5d312d9893258f59&auto=format&fit=crop&w=1355&q=80'
22
+  ];
23
+
24
+  @override
25
+  Widget build(BuildContext context) {
26
+    return Container(
27
+      decoration: const BoxDecoration(color: Colors.white),
28
+      padding: EdgeInsets.all(15.w),
29
+      child: Column(
30
+        children: [
31
+          const headers(),
32
+          //banner
33
+          Container(
34
+            margin: EdgeInsets.fromLTRB(0, 15.h, 0, 15.h),
35
+            child: CarouselSlider(
36
+              items: imgList
37
+                  .map((item) => Container(
38
+                        child: Center(
39
+                            child: Image.network(item,
40
+                                fit: BoxFit.cover, width: 345.w)),
41
+                      ))
42
+                  .toList(),
43
+              options: CarouselOptions(
44
+                autoPlay: true,
45
+                enlargeCenterPage: false, //图片中心放大
46
+                viewportFraction: 1, //每个页面应占据的视口部分。默认为 0.8,这意味着每个页面填充 80% 的轮播。
47
+                // aspectRatio: 1.6,//纵横比
48
+                height: 214.w,
49
+                initialPage: 1, //初始页
50
+              ),
51
+            ),
52
+          ),
53
+          Container(
54
+            margin: EdgeInsets.fromLTRB(0, 15.h, 0, 20.h),
55
+            child: Row(
56
+              children: [
57
+                Padding(
58
+                  padding: EdgeInsets.fromLTRB(0, 0, 10.w, 0),
59
+                  child: Image.asset(
60
+                    'images/index/orderList.png',
61
+                    width: 20.w,
62
+                  ),
63
+                ),
64
+                Text(
65
+                  '作业列表',
66
+                  style: TextStyle(
67
+                      color: Color(0xff222222),
68
+                      fontSize: 20.sp,
69
+                      fontWeight: FontWeight.w800),
70
+                )
71
+              ],
72
+            ),
73
+          ),
74
+          Container(
75
+            margin: EdgeInsets.fromLTRB(0, 0, 0, 15.h),
76
+            padding: EdgeInsets.all(20.w),
77
+            width: 345.w,
78
+            height: 90.h,
79
+            decoration: BoxDecoration(
80
+              color: Colors.white,
81
+              boxShadow: [
82
+                BoxShadow(
83
+                    color: Color(0xE2000000),
84
+                    offset: Offset(0, 0),
85
+                    blurRadius: 22.w)
86
+              ],
87
+              borderRadius: BorderRadius.all(Radius.circular(20.w)),
88
+            ),
89
+            child: Stack(
90
+              children: [
91
+                Positioned(
92
+                    top: -122.w,
93
+                    left: -134.w,
94
+                    child: Container(
95
+                      width: 225.w,
96
+                      height: 217.w,
97
+                      decoration: BoxDecoration(
98
+                        borderRadius: BorderRadius.all(Radius.circular(137.w)),
99
+                        border: Border.all(width: 1.w,color: Color(0xFFc7c7c7),style: BorderStyle.solid),
100
+                        gradient: LinearGradient(
101
+                          colors: [
102
+                            Color(0xFF8f8f8f),
103
+                            Color(0xFFc0c0c0),
104
+                          ],
105
+                        ),
106
+                      ),
107
+                    ),
108
+                ),
109
+
110
+              ],
111
+            ),
112
+          ),
113
+        ],
114
+      ),
115
+    );
116
+  }
117
+}

+ 64
- 0
lib/pages/home/widgets/home/widgets/headers.dart Bestand weergeven

@@ -0,0 +1,64 @@
1
+import 'package:flutter/material.dart';
2
+import 'package:flutter_screenutil/flutter_screenutil.dart';
3
+import 'package:get/get.dart';
4
+
5
+class headers extends StatelessWidget {
6
+  const headers({Key? key}) : super(key: key);
7
+
8
+  @override
9
+  Widget build(BuildContext context) {
10
+    return Row(
11
+      children: [
12
+        Image.asset(
13
+          'images/index/position.png',
14
+          width: 14.w,
15
+          height: 14.w,
16
+        ),
17
+        Padding(
18
+          padding: EdgeInsets.fromLTRB(4.5.w, 0, 5.w, 0),
19
+          child: Text(
20
+            '邓州市',
21
+            style: TextStyle(
22
+              color: const Color(0xff202020),
23
+              fontSize: 16.sp,
24
+              fontWeight: FontWeight.bold,
25
+            ),
26
+          ),
27
+        ),
28
+        const Icon(Icons.arrow_drop_down),
29
+        Container(
30
+          margin: EdgeInsets.fromLTRB(15.w, 0, 0, 0),
31
+          padding: EdgeInsets.symmetric(vertical: 0, horizontal: 15.w),
32
+          width: 246.w,
33
+          height: 34.h,
34
+          decoration: const BoxDecoration(
35
+            color: Color(0x30cccccc),
36
+            borderRadius: BorderRadius.all(Radius.circular(25)),
37
+          ),
38
+          child: GestureDetector(
39
+            onTap: () {
40
+              // Get.toNamed('/searchPage');
41
+            },
42
+            child: Row(
43
+              children: [
44
+                Container(
45
+                  margin: EdgeInsets.fromLTRB(0, 0, 3.w, 0),
46
+                  child: Image.asset(
47
+                    'images/index/search.png',
48
+                    width: 15.w,
49
+                    height: 15.w,
50
+                  ),
51
+                ),
52
+                Text(
53
+                  '请输入关键字查询订单',
54
+                  style: TextStyle(
55
+                      color: const Color(0xFFB6B6B6), fontSize: 14.sp),
56
+                ),
57
+              ],
58
+            ),
59
+          ),
60
+        ),
61
+      ],
62
+    );
63
+  }
64
+}

+ 2
- 0
lib/pages/index.dart Bestand weergeven

@@ -2,3 +2,5 @@
2 2
 export 'home/index.dart';
3 3
 export 'splash/splash.dart';
4 4
 export 'Login/index.dart';
5
+export 'order/index.dart';
6
+export 'main/index.dart';

+ 14
- 0
lib/pages/main/index.dart Bestand weergeven

@@ -0,0 +1,14 @@
1
+import 'package:flutter/material.dart';
2
+import 'package:worker_client/widgets/layout/BasicPage.dart';
3
+
4
+class Main extends BasicPage {
5
+  Main({Key? key}) : super(key: key) {
6
+    tabIndex = 2;
7
+    naviTitle = '我的';
8
+  }
9
+
10
+  @override
11
+  Widget builder(BuildContext context) {
12
+    return const Text('我是个人中心页面');
13
+  }
14
+}

+ 15
- 0
lib/pages/order/index.dart Bestand weergeven

@@ -0,0 +1,15 @@
1
+import 'package:flutter/material.dart';
2
+import 'package:worker_client/widgets/layout/BasicPage.dart';
3
+
4
+
5
+class Order extends BasicPage {
6
+  Order({Key? key}) : super(key: key) {
7
+    tabIndex = 1;
8
+    naviTitle = '订单列表';
9
+  }
10
+
11
+  @override
12
+  Widget builder(BuildContext context) {
13
+    return Text('我是订单列表页面');
14
+  }
15
+}

+ 1
- 3
lib/pages/splash/splash.dart Bestand weergeven

@@ -1,9 +1,7 @@
1 1
 import 'package:flutter/material.dart';
2
-
3 2
 import '../splash/widgets/countdown.dart';
4 3
 import 'package:get/get.dart';
5 4
 import 'package:flutter_screenutil/flutter_screenutil.dart';
6
-
7 5
 import '../home/index.dart';
8 6
 
9 7
 class SplashScreen extends StatefulWidget {
@@ -15,7 +13,7 @@ class SplashScreen extends StatefulWidget {
15 13
 
16 14
 class _SplashScreen extends State<SplashScreen> {
17 15
   handleOnFinish() {
18
-    Get.off(const Home());
16
+    Get.off(Home());
19 17
   }
20 18
 
21 19
   @override

+ 13
- 20
lib/pages/splash/widgets/countdown.dart Bestand weergeven

@@ -19,26 +19,19 @@ Widget countdown(int sec, void Function() onFinish) {
19 19
   }, 1000);
20 20
 
21 21
   return Obx(
22
-    () => GestureDetector(
23
-      onTap: () {
24
-        _timer.cancel();
25
-        // return;
26
-        // onFinish();
27
-      },
28
-      child: Container(
29
-        width: 50.w,
30
-        height: 30.h,
31
-        alignment: const Alignment(0, 0),
32
-        decoration: const BoxDecoration(
33
-            borderRadius: BorderRadius.all(Radius.circular(20)),
34
-            color: Color(0x77222222)),
35
-        child: Text(
36
-          _countdown.value.toString() + '跳过',
37
-          style: TextStyle(
38
-              fontSize: 13.sp,
39
-              letterSpacing: 2,
40
-              color: const Color(0xFFFFFFFF),
41
-              ),
22
+    () => Container(
23
+      width: 20.h,
24
+      height: 20.h,
25
+      alignment: const Alignment(0, 0),
26
+      decoration: const BoxDecoration(
27
+          borderRadius: BorderRadius.all(Radius.circular(20)),
28
+          color: Color(0x77222222)),
29
+      child: Text(
30
+        _countdown.value.toString(),
31
+        style: TextStyle(
32
+          fontSize: 13.sp,
33
+          letterSpacing: 2,
34
+          color: const Color(0xFFFFFFFF),
42 35
         ),
43 36
       ),
44 37
     ),

+ 9
- 10
lib/routes/middleWares.dart Bestand weergeven

@@ -4,14 +4,13 @@ import 'package:get/get.dart';
4 4
 import 'package:get_storage/get_storage.dart';
5 5
 
6 6
 void routingCallback (routing) {
7
-  GetStorage box = GetStorage();
8
-  bool isLogin = box.hasData('token');
9
-  bool isSplashScreen = routing?.current == '/splash';
10
-  bool isLoginPage = routing?.current == '/login';
11
-  print(99999999);
12
-  if (!isLogin && !isSplashScreen && !isLoginPage) {
13
-    // addPostFrameCallback 作用是等当前帧绘制完成之后再加载
14
-    // https://github.com/jonataslaw/getx/issues/262
15
-    SchedulerBinding.instance?.addPostFrameCallback((_) => Get.offNamed('/login'));
16
-  }
7
+  // GetStorage box = GetStorage();
8
+  // bool isLogin = box.hasData('token');
9
+  // bool isSplashScreen = routing?.current == '/splash';
10
+  // bool isLoginPage = routing?.current == '/login';
11
+  // if (!isLogin && !isSplashScreen && !isLoginPage) {
12
+  //   // addPostFrameCallback 作用是等当前帧绘制完成之后再加载
13
+  //   // https://github.com/jonataslaw/getx/issues/262
14
+  //   SchedulerBinding.instance?.addPostFrameCallback((_) => Get.offNamed('/login'));
15
+  // }
17 16
 }

+ 9
- 2
lib/routes/pages.dart Bestand weergeven

@@ -1,9 +1,16 @@
1 1
 
2 2
 import 'package:get/get.dart';
3
+import 'package:get_storage/get_storage.dart';
3 4
 import '../pages/index.dart';
4 5
 
5 6
 List<GetPage> pages = [
6
-  GetPage(name: '/', page: () =>  Home()),
7
-  GetPage(name: '/splash', page: () => SplashScreen()),
7
+  GetPage(name: '/', page: () {
8
+    GetStorage box = GetStorage();
9
+    return box.hasData('token') ? Home() : Login();
10
+  }),
11
+  // GetPage(name: '/splash', page: () => SplashScreen()),
8 12
   GetPage(name: '/login', page: () =>  const Login()),
13
+  GetPage(name: '/order', page: () =>  Order()),
14
+  GetPage(name: '/', page: () =>  Home()),
15
+  GetPage(name: '/main', page: () =>  Main()),
9 16
 ];

+ 22
- 0
lib/theme.dart Bestand weergeven

@@ -0,0 +1,22 @@
1
+
2
+import 'package:flutter/material.dart';
3
+import 'package:flutter_screenutil/flutter_screenutil.dart';
4
+
5
+ThemeData getTheme() {
6
+  return ThemeData(
7
+    appBarTheme: AppBarTheme(
8
+      centerTitle: true,
9
+      backgroundColor: Colors.transparent,
10
+      foregroundColor: const Color(0xFF333333),
11
+      elevation: 0,
12
+      toolbarHeight: 44.w,
13
+      titleTextStyle: TextStyle(
14
+        color: const Color(0xFF333333),
15
+        fontWeight: FontWeight.bold,
16
+        fontSize: 17.sp,
17
+        letterSpacing: 2
18
+      ),
19
+    ),
20
+    backgroundColor: Colors.white,
21
+  );
22
+}

+ 14
- 19
lib/utils/Request.dart Bestand weergeven

@@ -20,10 +20,10 @@ class Response {
20 20
       Response.fromMap(jsonDecode(str) as Map<String, dynamic>);
21 21
 
22 22
   factory Response.fromMap(Map<String, dynamic> resp) => Response(
23
-    code: resp['code'],
24
-    message: resp['message'],
25
-    data: resp['data'],
26
-  );
23
+        code: resp['code'],
24
+        message: resp['message'],
25
+        data: resp['data'],
26
+      );
27 27
 }
28 28
 
29 29
 final client = GetPlatform.isAndroid ? 'android' : 'ios';
@@ -38,12 +38,8 @@ Dio createRequest() {
38 38
   var dio = Dio(options);
39 39
   dio.interceptors.add(InterceptorsWrapper(onRequest: (options, handler) {
40 40
     // Do something before request is sent
41
-    options.headers['Authorization'] =  GetStorage().read("token");
41
+    options.headers['Authorization'] = GetStorage().read("token");
42 42
     return handler.next(options); //continue
43
-    // If you want to resolve the request with some custom data,
44
-    // you can resolve a `Response` object eg: `handler.resolve(response)`.
45
-    // If you want to reject the request with a error message,
46
-    // you can reject a `DioError` object eg: `handler.reject(dioError)`
47 43
   }, onResponse: (response, handler) {
48 44
     var resp = response.data as Map<String, dynamic>;
49 45
     if (resp['code'] == 1000) {
@@ -60,14 +56,14 @@ Dio createRequest() {
60 56
 
61 57
       return handler.next(response);
62 58
     } else {
63
-      DioError error = DioError(requestOptions: response.requestOptions, error: response.data, response: response);
59
+      DioError error = DioError(
60
+          requestOptions: response.requestOptions,
61
+          error: response.data,
62
+          response: response);
64 63
       return handler.reject(error);
65 64
     }
66 65
   }, onError: (DioError e, handler) {
67
-    // Do something with response error
68 66
     return handler.next(e); //continue
69
-    // If you want to resolve the request with some custom data,
70
-    // you can resolve a `Response` object eg: `handler.resolve(response)`.
71 67
   }));
72 68
 
73 69
   return dio;
@@ -77,12 +73,11 @@ var instance = createRequest();
77 73
 
78 74
 Future request(String path,
79 75
     {data,
80
-      Map<String, dynamic>? queryParameters,
81
-      CancelToken? cancelToken,
82
-      Options? options,
83
-      ProgressCallback? onSendProgress,
84
-      ProgressCallback? onReceiveProgress}) async {
85
-
76
+    Map<String, dynamic>? queryParameters,
77
+    CancelToken? cancelToken,
78
+    Options? options,
79
+    ProgressCallback? onSendProgress,
80
+    ProgressCallback? onReceiveProgress}) async {
86 81
   var resp = await instance.request(path,
87 82
       data: data,
88 83
       queryParameters: queryParameters,

+ 94
- 0
lib/widgets/DefaultButton.dart Bestand weergeven

@@ -0,0 +1,94 @@
1
+import 'package:flutter/material.dart';
2
+
3
+
4
+
5
+class DefaultButton extends StatefulWidget {
6
+  //点击回调
7
+  final GestureTapCallback onPressed;
8
+  final String text;
9
+  final EdgeInsetsGeometry margin;
10
+  final double width;
11
+  final double height;
12
+  final double? fontSize;
13
+  final Color backColor;
14
+  final Color color;
15
+  final double? radius;
16
+
17
+  EdgeInsetsGeometry marginDefault =
18
+  const EdgeInsets.fromLTRB(0, 90.0, 0, 30); //按钮默认的margin值
19
+
20
+  DefaultButton({
21
+    Key? key,
22
+    required this.onPressed,
23
+    required this.text,
24
+    required this.margin,
25
+    required this.width,
26
+    required this.height,
27
+    this.fontSize,
28
+    this.radius,
29
+    required this.backColor,
30
+    required this.color,
31
+  }) : super(key: key);
32
+
33
+  @override
34
+  State createState() {
35
+    if (margin == null) {
36
+      return _DefaultButtonState(onPressed, text, marginDefault,width,height,fontSize,backColor,color,radius);
37
+    }
38
+    return _DefaultButtonState(onPressed, text, margin,width,height,fontSize,backColor,color,radius);
39
+  }
40
+}
41
+
42
+class _DefaultButtonState extends State<DefaultButton> {
43
+  //点击回调
44
+  final GestureTapCallback onPressed;
45
+  final String text;
46
+  final EdgeInsetsGeometry margin;
47
+  final double width;
48
+  final double height;
49
+  final double? fontSize;
50
+  final Color backColor;
51
+  final Color color;
52
+  final double? radius;
53
+  _DefaultButtonState(
54
+      this.onPressed,
55
+      this.text,
56
+      this.margin,
57
+      this.width,
58
+      this.height,
59
+      this.fontSize,
60
+      this.backColor,
61
+      this.color,
62
+      this.radius
63
+      );
64
+
65
+  @override
66
+  Widget build(BuildContext context) {
67
+    Widget _SectionBtn = Container(
68
+      margin: margin,
69
+      child: SizedBox(
70
+        width: width,
71
+        height: height,
72
+        child: RaisedButton(
73
+          color: backColor,
74
+          disabledColor: const Color(0xF5F6F7ff),
75
+          disabledTextColor: const Color(0xF5F6F7ff),
76
+          colorBrightness: Brightness.dark,
77
+          shape:
78
+          RoundedRectangleBorder(borderRadius: BorderRadius.circular(radius??5)),
79
+          child: Text(text,style:  TextStyle(
80
+              fontSize: fontSize,
81
+              fontWeight: FontWeight.bold,
82
+              color: color,
83
+          ),),
84
+          textColor: Colors.white,
85
+          onPressed: onPressed,
86
+        ),
87
+      ),
88
+    );
89
+
90
+    return _SectionBtn;
91
+  }
92
+
93
+}
94
+

+ 174
- 0
lib/widgets/Modal.dart Bestand weergeven

@@ -0,0 +1,174 @@
1
+
2
+import 'package:flutter/cupertino.dart';
3
+import 'package:flutter/material.dart';
4
+import 'package:flutter/widgets.dart';
5
+import 'package:flutter_screenutil/flutter_screenutil.dart';
6
+import 'package:get/get.dart';
7
+
8
+typedef ModalFunc = dynamic Function();
9
+
10
+/// func 函数如果返回 bool 值, 则只有 true 的情况下才默认关闭弹窗
11
+/// 如果返回 Future , 则只有正常结束的时候 才关闭弹窗
12
+/// 其余情况, 都默认关闭弹窗
13
+void _handleFunc(ModalFunc? func) {
14
+  if (null != func) {
15
+    dynamic res = func();
16
+    if (res.runtimeType == bool) {
17
+      if (res) {
18
+        Get.back(closeOverlays: true);
19
+      }
20
+    } else if (res is Future) {
21
+      res.then((_) => Get.back(closeOverlays: true));
22
+    } else {
23
+      Get.back(closeOverlays: true);
24
+    }
25
+  } else {
26
+    Get.back(closeOverlays: true);
27
+  }
28
+}
29
+
30
+/// 打开一个 dialog
31
+void showDialog({ required String title, String? message, Widget? content, ModalFunc? onConfirm, ModalFunc? onCancel }) {
32
+  Get.dialog(
33
+    Modal(
34
+      type: 'dialog',
35
+      title: title,
36
+      message: message,
37
+      content: content,
38
+      onConfirm: () => _handleFunc(onConfirm),
39
+      onCancel: () => _handleFunc(onCancel),
40
+    )
41
+  );
42
+}
43
+
44
+/// 打开一个 alert
45
+void showAlert({ required String title, String? message, Widget? content, ModalFunc? onConfirm }) {
46
+  Get.dialog(
47
+      Modal(
48
+        type: 'alert',
49
+        title: title,
50
+        message: message,
51
+        content: content,
52
+        onConfirm: () => _handleFunc(onConfirm),
53
+      )
54
+  );
55
+}
56
+
57
+class Modal extends StatelessWidget {
58
+
59
+  String title;
60
+  String type;
61
+  String? message;
62
+  Widget? content;
63
+  VoidCallback? onConfirm;
64
+  VoidCallback? onCancel;
65
+
66
+  final _titleStyle = TextStyle(color: const Color(0xFF222222), fontSize: 20.sp, fontWeight: FontWeight.bold);
67
+  final _messageStyle = TextStyle(color: const Color(0xFF666666), fontSize: 18.sp);
68
+  final _primaryColor = const Color(0xFFFF703B);
69
+  final _btnSize = Size(90.w, 36.w);
70
+  final _btnShape = RoundedRectangleBorder(
71
+    side: const BorderSide(color: Color(0xFFFF703B), width: 2.0),
72
+    borderRadius: BorderRadius.all(Radius.circular(24.5.w)),
73
+  );
74
+
75
+  void _handleConfirm() {
76
+    if (null != onConfirm) {
77
+      onConfirm!();
78
+    }
79
+  }
80
+  void _handleCancel() {
81
+    if (null != onCancel) {
82
+      onCancel!();
83
+    }
84
+  }
85
+
86
+  Modal({Key? key,
87
+    this.type = 'alert',
88
+    required this.title,
89
+    this.message,
90
+    this.content,
91
+    this.onConfirm,
92
+    this.onCancel,
93
+  }): super(key: key);
94
+
95
+  Widget _confirmBtn() {
96
+    return ElevatedButton(
97
+      child: Text("确定", style: TextStyle(color: Colors.white, fontSize: 18.sp, letterSpacing: 5.sp)),
98
+      style: ElevatedButton.styleFrom(
99
+          primary: _primaryColor,
100
+          elevation: 0,
101
+          minimumSize: _btnSize,
102
+          shape: _btnShape,
103
+      ),
104
+      onPressed: _handleConfirm,
105
+    );
106
+  }
107
+
108
+  Widget _cancelBtn() {
109
+    return ElevatedButton(
110
+      child: Text("取消", style: TextStyle(color: _primaryColor, fontSize: 18.sp, letterSpacing: 5.sp)),
111
+      style: ElevatedButton.styleFrom(
112
+        primary: Colors.white,
113
+        elevation: 0,
114
+        minimumSize: _btnSize,
115
+        shape: _btnShape,
116
+      ),
117
+      onPressed: _handleCancel,
118
+    );
119
+  }
120
+
121
+  Widget _alert() {
122
+    return SimpleDialog(
123
+      shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(24.w)),
124
+      titleTextStyle: _titleStyle,
125
+      title: Text(title, textAlign: TextAlign.center),
126
+        children: [
127
+          if (null != message) Text(message!, textAlign: TextAlign.center, style: _messageStyle),
128
+          if (null != content) content!,
129
+          SizedBox(height: 16.w),
130
+          Center(
131
+            child: _confirmBtn(),
132
+          ),
133
+          SizedBox(height: 10.w),
134
+        ]
135
+    );
136
+  }
137
+
138
+  Widget _dialog() {
139
+    Widget hSpacer = SizedBox(width: 16.w);
140
+
141
+    return SimpleDialog(
142
+        shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(24.w)),
143
+        titleTextStyle: _titleStyle,
144
+        title: Text(title, textAlign: TextAlign.center),
145
+        alignment: Alignment.center,
146
+        children: [
147
+          if (null != message) Text(message!, textAlign: TextAlign.center, style: _messageStyle),
148
+          if (null != content) content!,
149
+          SizedBox(height: 16.w),
150
+          Row(
151
+            mainAxisAlignment: MainAxisAlignment.center,
152
+            children: [
153
+              hSpacer,
154
+              Center(
155
+                child: _confirmBtn(),
156
+              ),
157
+              hSpacer,
158
+              Center(
159
+                child: _cancelBtn(),
160
+              ),
161
+              hSpacer,
162
+            ],
163
+          ),
164
+          SizedBox(height: 10.w),
165
+        ]
166
+    );
167
+  }
168
+
169
+  @override
170
+  Widget build(BuildContext context) {
171
+    return type == 'alert' ? _alert() : _dialog();
172
+  }
173
+
174
+}

+ 33
- 0
lib/widgets/NullCard.dart Bestand weergeven

@@ -0,0 +1,33 @@
1
+import 'package:flutter/material.dart';
2
+import 'package:flutter_screenutil/flutter_screenutil.dart';
3
+
4
+class NullCard extends StatelessWidget {
5
+  final String text;
6
+  const NullCard({Key? key, required this.text}) : super(key: key);
7
+  @override
8
+  Widget build(BuildContext context) {
9
+    return Container(
10
+      width: 345.w,
11
+      padding: EdgeInsets.all(30.w),
12
+      alignment: Alignment.center,
13
+      child: Column(
14
+        children: [
15
+          Container(
16
+            margin: EdgeInsets.fromLTRB(0, 0, 0, 22.h),
17
+            child: Image.asset(
18
+              'images/noData.png',
19
+              width: 135.w,
20
+            ),
21
+          ),
22
+          Text(
23
+            text,
24
+            style: TextStyle(
25
+                fontSize: 17.sp, color: Color(0xFFb4b4b4)),
26
+          )
27
+        ],
28
+      ),
29
+    );
30
+  }
31
+
32
+
33
+}

+ 112
- 0
lib/widgets/layout/BasicPage.dart Bestand weergeven

@@ -0,0 +1,112 @@
1
+
2
+import '/widgets/layout/bottomBar/BottomBar.dart';
3
+import 'package:flutter/material.dart';
4
+import 'package:get/get.dart';
5
+
6
+import 'barList.dart';
7
+
8
+abstract class BasicPage extends StatefulWidget {
9
+  // 导航标题
10
+  // 用法 naviTitle = xxxx
11
+  final _title = Rx<String>("");
12
+  set naviTitle(String t) {
13
+    _title.value = t;
14
+  }
15
+
16
+  // 当前活动 tab
17
+  // 如果非 tab 页, 则不传
18
+  int? tabIndex;
19
+
20
+  // 允许滚动 - 不是响应式的
21
+  bool canScroll;
22
+
23
+  //
24
+  BasicPage({Key? key, this.canScroll = true, this.tabIndex }) : super(key: key);
25
+
26
+  @protected
27
+  Widget builder(BuildContext context);
28
+
29
+  // 将要展示
30
+  @protected
31
+  @mustCallSuper
32
+  void beforeShow() {
33
+    assert(() {
34
+      print("===========beforeShow===========");
35
+      return true;
36
+    }());
37
+  }
38
+
39
+  @protected
40
+  @mustCallSuper
41
+  void beforeHide() {
42
+    assert(() {
43
+      print("===========beforeHide===========");
44
+      return true;
45
+    }());
46
+  }
47
+
48
+  @protected
49
+  @mustCallSuper
50
+  void beforeUnmounted() {
51
+    assert(() {
52
+      print("===========beforeUnmounted===========");
53
+      return true;
54
+    }());
55
+  }
56
+
57
+  @override
58
+  State<BasicPage> createState() => _BasicPageState();
59
+}
60
+
61
+class _BasicPageState extends State<BasicPage> {
62
+
63
+  @override
64
+  void initState() {
65
+    super.initState();
66
+  }
67
+
68
+  @override
69
+  void didChangeDependencies() {
70
+    super.didChangeDependencies();
71
+    widget.beforeShow();
72
+  }
73
+
74
+  @override
75
+  void deactivate() {
76
+    super.deactivate();
77
+    widget.beforeHide();
78
+  }
79
+
80
+  @override
81
+  void dispose() {
82
+    super.dispose();
83
+    widget.beforeUnmounted();
84
+  }
85
+
86
+  // appBar 的样式请查询 theme 文件
87
+  PreferredSizeWidget? _getAppBar() {
88
+    return AppBar(title: Obx(() => Text(widget._title.value)));
89
+  }
90
+
91
+  Widget _buildChild(BuildContext context) {
92
+    if (widget.canScroll) {
93
+      return SingleChildScrollView(
94
+        child: widget.builder(context),
95
+      );
96
+    } else {
97
+      return widget.builder(context);
98
+    }
99
+  }
100
+
101
+  @override
102
+  Widget build(BuildContext context) {
103
+    return Scaffold(
104
+      appBar: _getAppBar(),
105
+      body: SafeArea(
106
+        child: _buildChild(context),
107
+      ),
108
+      bottomNavigationBar: widget.tabIndex == null ? null : BottomBar(list: BarList, current: widget.tabIndex!),
109
+    );
110
+  }
111
+}
112
+

+ 25
- 0
lib/widgets/layout/barList.dart Bestand weergeven

@@ -0,0 +1,25 @@
1
+import 'dart:ui';
2
+import 'package:flutter_screenutil/flutter_screenutil.dart';
3
+
4
+import 'bottomBar/item.dart';
5
+
6
+final BarList = <BarItem>[
7
+  BarItem(
8
+    label: '首页',
9
+    page: '/',
10
+    normal: Item (color: const Color(0xFF323232), fontSize: 15.sp, image: 'images/index/index.png'),
11
+    selected: Item (color: const Color(0xFF06B03B), fontSize: 15.sp, image: 'images/index/indexActive.png'),
12
+  ),
13
+  BarItem(
14
+    label: '订单列表',
15
+    page: '/order',
16
+    normal: Item (color: const Color(0xFF323232), fontSize: 15.sp, image: 'images/index/job.png'),
17
+    selected: Item (color: const Color(0xFF06B03B), fontSize: 15.sp, image: 'images/index/jobActive.png'),
18
+  ),
19
+  BarItem(
20
+    label: '个人中心',
21
+    page: '/main',
22
+    normal: Item (color: const Color(0xFF323232), fontSize: 15.sp, image: 'images/index/user.png'),
23
+    selected: Item (color: const Color(0xFF06B03B), fontSize: 15.sp, image: 'images/index/userActive.png'),
24
+  ),
25
+];

+ 86
- 0
lib/widgets/layout/bottomBar/BottomBar.dart Bestand weergeven

@@ -0,0 +1,86 @@
1
+
2
+import 'package:flutter/widgets.dart';
3
+import 'package:flutter_screenutil/flutter_screenutil.dart';
4
+import 'package:get/get.dart';
5
+import 'item.dart';
6
+
7
+class BottomBarItem extends StatelessWidget {
8
+
9
+  final bool selected;
10
+  final BarItem data;
11
+
12
+  BottomBarItem({Key? key, required this.selected, required this.data }) : super(key: key);
13
+
14
+  @override
15
+  Widget build(BuildContext context) {
16
+    final image = selected ? data.selected.image : data.normal.image;
17
+    final color = selected ? data.selected.color : data.normal.color;
18
+    final fontSize = selected ? data.selected.fontSize : data.normal.fontSize;
19
+
20
+    final textStyle = TextStyle(color: color, fontSize: fontSize, fontWeight: FontWeight.bold);
21
+
22
+    return GestureDetector(
23
+      onTap: () {
24
+        if (!selected) {
25
+          Get.offNamed(data.page);
26
+        }
27
+      },
28
+      child: Column(
29
+        children: [
30
+          Expanded(
31
+            flex: 1,
32
+            child: Image.asset(image, fit: BoxFit.cover),
33
+          ),
34
+          Expanded(
35
+            flex: 1,
36
+            child: Center(
37
+              child: Text(data.label, style: textStyle),
38
+            ),
39
+          ),
40
+        ],
41
+      ),
42
+    );
43
+  }
44
+}
45
+
46
+class BottomBar extends StatelessWidget {
47
+
48
+  final int current;
49
+  List<BarItem> list;
50
+
51
+  BottomBar({ Key? key , required this.list, required this.current }) : super(key: key);
52
+
53
+  @override
54
+  Widget build(BuildContext context) {
55
+    return Container(
56
+      width: double.infinity,
57
+      height: 65.w,
58
+      padding: EdgeInsets.symmetric(vertical: 10.w, horizontal: 0),
59
+      decoration: BoxDecoration(
60
+        color: const Color(0xFFFFFFFF),
61
+        boxShadow: [
62
+          BoxShadow(
63
+            color: const Color(0x14000000),
64
+            offset: Offset(0, -2.w),
65
+            blurRadius: 3.w,
66
+          ),
67
+        ],
68
+      ),
69
+      child: Center(
70
+        child: Row(
71
+          children: [
72
+            ...list.map((item) {
73
+              int index = list.indexOf(item);
74
+
75
+              return Expanded(
76
+                  flex: 1,
77
+                  child: BottomBarItem(data: item, selected: current == index ),
78
+              );
79
+            })
80
+          ],
81
+        ),
82
+      ),
83
+    );
84
+  }
85
+
86
+}

+ 19
- 0
lib/widgets/layout/bottomBar/item.dart Bestand weergeven

@@ -0,0 +1,19 @@
1
+
2
+import 'dart:ui';
3
+
4
+class Item {
5
+  double fontSize;
6
+  Color color;
7
+  String image;
8
+
9
+  Item({ required this.fontSize, required this.color, required this.image });
10
+}
11
+
12
+class BarItem {
13
+  String label;
14
+  String page;
15
+  Item normal;
16
+  Item selected;
17
+
18
+  BarItem ({ required this.label, required this.page, required this.normal, required this.selected });
19
+}

+ 15
- 8
pubspec.lock Bestand weergeven

@@ -7,14 +7,14 @@ packages:
7 7
       name: _fe_analyzer_shared
8 8
       url: "https://pub.flutter-io.cn"
9 9
     source: hosted
10
-    version: "38.0.0"
10
+    version: "39.0.0"
11 11
   analyzer:
12 12
     dependency: transitive
13 13
     description:
14 14
       name: analyzer
15 15
       url: "https://pub.flutter-io.cn"
16 16
     source: hosted
17
-    version: "3.4.1"
17
+    version: "4.0.0"
18 18
   args:
19 19
     dependency: transitive
20 20
     description:
@@ -42,7 +42,7 @@ packages:
42 42
       name: build
43 43
       url: "https://pub.flutter-io.cn"
44 44
     source: hosted
45
-    version: "2.2.1"
45
+    version: "2.3.0"
46 46
   build_config:
47 47
     dependency: transitive
48 48
     description:
@@ -50,6 +50,13 @@ packages:
50 50
       url: "https://pub.flutter-io.cn"
51 51
     source: hosted
52 52
     version: "1.0.0"
53
+  carousel_slider:
54
+    dependency: "direct main"
55
+    description:
56
+      name: carousel_slider
57
+      url: "https://pub.flutter-io.cn"
58
+    source: hosted
59
+    version: "4.0.0"
53 60
   characters:
54 61
     dependency: transitive
55 62
     description:
@@ -112,7 +119,7 @@ packages:
112 119
       name: dart_style
113 120
       url: "https://pub.flutter-io.cn"
114 121
     source: hosted
115
-    version: "2.2.2"
122
+    version: "2.2.3"
116 123
   dio:
117 124
     dependency: "direct main"
118 125
     description:
@@ -159,7 +166,7 @@ packages:
159 166
       name: flutter_screenutil
160 167
       url: "https://pub.flutter-io.cn"
161 168
     source: hosted
162
-    version: "5.4.0"
169
+    version: "5.4.0+1"
163 170
   flutter_test:
164 171
     dependency: "direct dev"
165 172
     description: flutter
@@ -225,7 +232,7 @@ packages:
225 232
       name: json_serializable
226 233
       url: "https://pub.flutter-io.cn"
227 234
     source: hosted
228
-    version: "6.1.5"
235
+    version: "6.1.6"
229 236
   lints:
230 237
     dependency: transitive
231 238
     description:
@@ -391,14 +398,14 @@ packages:
391 398
       name: source_gen
392 399
       url: "https://pub.flutter-io.cn"
393 400
     source: hosted
394
-    version: "1.2.1"
401
+    version: "1.2.2"
395 402
   source_helper:
396 403
     dependency: transitive
397 404
     description:
398 405
       name: source_helper
399 406
       url: "https://pub.flutter-io.cn"
400 407
     source: hosted
401
-    version: "1.3.1"
408
+    version: "1.3.2"
402 409
   source_span:
403 410
     dependency: transitive
404 411
     description:

+ 4
- 18
pubspec.yaml Bestand weergeven

@@ -41,7 +41,7 @@ dependencies:
41 41
   location: ^4.3.0
42 42
   fluttertoast: ^8.0.9
43 43
   get_storage: ^2.0.3
44
-
44
+  carousel_slider: ^4.0.0
45 45
 dev_dependencies:
46 46
   flutter_test:
47 47
     sdk: flutter
@@ -66,23 +66,9 @@ flutter:
66 66
   # the material Icons class.
67 67
   uses-material-design: true
68 68
   assets:
69
-    - images/login/loginImg.png
70
-    - images/login/VerificationCode.png
71
-    - images/login/checkedImg.png
72
-    - images/login/unChecked.png
73
-    - images/index/borderImg.png
74
-    - images/index/goback.png
75
-    - images/index/index.png
76
-    - images/index/indexActive.png
77
-    - images/index/job.png
78
-    - images/index/jobActive.png
79
-    - images/index/orderList.png
80
-    - images/index/position.png
81
-    - images/index/search.png
82
-    - images/index/user.png
83
-    - images/index/userActive.png
84
-    - images/splash.png
85
-    - images/logo.png
69
+    - images/login/
70
+    - images/index/
71
+    - images/
86 72
   # To add assets to your application, add an assets section, like this:
87 73
   # assets:
88 74
   #   - images/a_dot_burr.jpeg