[baozhangchao] 3 anos atrás
pai
commit
3afaa5479c
6 arquivos alterados com 244 adições e 82 exclusões
  1. 8
    0
      lib/services/user.dart
  2. 45
    34
      lib/utils/Request.dart
  3. 54
    0
      lib/widgets/Cell.dart
  4. 88
    0
      lib/widgets/GradientButton.dart
  5. 48
    48
      pubspec.lock
  6. 1
    0
      pubspec.yaml

+ 8
- 0
lib/services/user.dart Ver arquivo

@@ -0,0 +1,8 @@
1
+
2
+import 'package:dio/dio.dart';
3
+import 'package:farmer_client/utils/Request.dart';
4
+import 'package:flutter/foundation.dart';
5
+
6
+Future getSMSCaptch(String phone) async {
7
+  return request('/sms-captcha', options: Options(method: 'POST'), queryParameters: { 'phone': phone });
8
+}

+ 45
- 34
lib/utils/Request.dart Ver arquivo

@@ -1,7 +1,8 @@
1
-
2 1
 import 'dart:convert';
3 2
 
4 3
 import 'package:dio/dio.dart';
4
+import 'package:flutter/foundation.dart';
5
+import 'package:get/get.dart';
5 6
 
6 7
 class Response {
7 8
   late int code;
@@ -14,56 +15,66 @@ class Response {
14 15
     this.data,
15 16
   });
16 17
 
17
-  factory Response.fromJson(dynamic str) => Response.fromMap(jsonDecode(str) as Map<String, dynamic>);
18
+  factory Response.fromJson(dynamic str) =>
19
+      Response.fromMap(jsonDecode(str) as Map<String, dynamic>);
18 20
 
19 21
   factory Response.fromMap(Map<String, dynamic> resp) => Response(
20
-    code: resp['code'],
21
-    message: resp['message'],
22
-    data: resp['data'],
23
-  );
22
+        code: resp['code'],
23
+        message: resp['message'],
24
+        data: resp['data'],
25
+      );
24 26
 }
25 27
 
28
+final client = GetPlatform.isAndroid ? 'android' : 'ios';
29
+
26 30
 Dio createRequest() {
27 31
   var options = BaseOptions(
28
-    baseUrl: 'https://www.xx.com/api',
32
+    baseUrl: 'https://machine.njyunzhi.com/api/' + client + '/farmer',
29 33
     connectTimeout: 5000,
30 34
     receiveTimeout: 3000,
31 35
   );
32 36
 
33 37
   var dio = Dio(options);
34
-  dio.interceptors.add(InterceptorsWrapper(
35
-      onRequest:(options, handler){
36
-        // Do something before request is sent
37
-        return handler.next(options); //continue
38
-        // If you want to resolve the request with some custom data,
39
-        // you can resolve a `Response` object eg: `handler.resolve(response)`.
40
-        // If you want to reject the request with a error message,
41
-        // you can reject a `DioError` object eg: `handler.reject(dioError)`
42
-      },
43
-      onResponse:(response,handler) {
44
-        Response resp = Response.fromJson(response.data['data']);
45
-        if (resp.code == 1000) {
46
-          response.data = resp.data;
47
-          return handler.next(response);
48
-        } else {
49
-          return handler.reject(response.data);
50
-        }
51
-      },
52
-      onError: (DioError e, handler) {
53
-        // Do something with response error
54
-        return  handler.next(e);//continue
55
-        // If you want to resolve the request with some custom data,
56
-        // you can resolve a `Response` object eg: `handler.resolve(response)`.
57
-      }
58
-  ));
38
+  dio.interceptors.add(InterceptorsWrapper(onRequest: (options, handler) {
39
+    // Do something before request is sent
40
+    return handler.next(options); //continue
41
+    // If you want to resolve the request with some custom data,
42
+    // you can resolve a `Response` object eg: `handler.resolve(response)`.
43
+    // If you want to reject the request with a error message,
44
+    // you can reject a `DioError` object eg: `handler.reject(dioError)`
45
+  }, onResponse: (response, handler) {
46
+    var resp = response.data as Map<String, dynamic>;
47
+    if (resp['code'] == 1000) {
48
+      response.data = resp['data'];
49
+      return handler.next(response);
50
+    } else {
51
+      return handler.reject(response.data);
52
+    }
53
+  }, onError: (DioError e, handler) {
54
+    // Do something with response error
55
+    return handler.next(e); //continue
56
+    // If you want to resolve the request with some custom data,
57
+    // you can resolve a `Response` object eg: `handler.resolve(response)`.
58
+  }));
59 59
 
60 60
   return dio;
61 61
 }
62 62
 
63 63
 var instance = createRequest();
64 64
 
65
-Future request (RequestOptions options) async {
66
-  var resp = await instance.fetch(options);
65
+Future request(String path,
66
+    {data,
67
+    Map<String, dynamic>? queryParameters,
68
+    CancelToken? cancelToken,
69
+    Options? options,
70
+    ProgressCallback? onSendProgress,
71
+    ProgressCallback? onReceiveProgress}) async {
72
+
73
+  var resp = await instance.request(path,
74
+      data: data,
75
+      queryParameters: queryParameters,
76
+      cancelToken: cancelToken,
77
+      options: options);
67 78
 
68 79
   if (resp.data.runtimeType == String) {
69 80
     String dt = resp.data as String;

+ 54
- 0
lib/widgets/Cell.dart Ver arquivo

@@ -0,0 +1,54 @@
1
+
2
+import 'package:flutter/cupertino.dart';
3
+import 'package:flutter/widgets.dart';
4
+import 'package:flutter_screenutil/flutter_screenutil.dart';
5
+
6
+class Cell extends StatelessWidget {
7
+  const Cell ({
8
+    Key? key,
9
+    this.header,
10
+    required this.child,
11
+    this.footer,
12
+    this.margin,
13
+  }) : super(key: key);
14
+
15
+  final Widget? header;
16
+  final Widget child;
17
+  final Widget? footer;
18
+  final EdgeInsetsGeometry? margin;
19
+
20
+  @override
21
+  Widget build(BuildContext context) {
22
+
23
+    return Container(
24
+      margin: margin,
25
+      padding: EdgeInsets.symmetric(vertical: 10.h, horizontal: 0.0),
26
+      decoration: const BoxDecoration(
27
+        border: Border(
28
+          bottom: BorderSide(width: 1.0, color: Color(0x1F000000)),
29
+        )
30
+      ),
31
+      child: Row(
32
+        children: [
33
+          if (null != header) SizedBox(
34
+            width: 53.w,
35
+            child: Container(
36
+              decoration: const BoxDecoration(
37
+                border: Border(
38
+                  right: BorderSide(width: 1, color: Color(0xFF333333))
39
+                )
40
+              ),
41
+              child: header,
42
+            ),
43
+          ),
44
+          Expanded(child: child,),
45
+          if (null != footer) ConstrainedBox (
46
+            constraints: BoxConstraints(maxWidth: 94.w),
47
+            child: footer,
48
+          )
49
+        ],
50
+      ),
51
+    );
52
+  }
53
+  
54
+}

+ 88
- 0
lib/widgets/GradientButton.dart Ver arquivo

@@ -0,0 +1,88 @@
1
+
2
+
3
+import 'package:flutter/material.dart';
4
+import 'package:flutter/widgets.dart';
5
+
6
+class GradientButton extends StatelessWidget {
7
+  const GradientButton({
8
+    Key? key,
9
+    this.colors,
10
+    this.linearStart,
11
+    this.linearEnd,
12
+    required this.onPressed,
13
+    required this.child,
14
+    this.padding,
15
+    this.borderRadius = const BorderRadius.all(Radius.circular(2)),
16
+    this.textColor,
17
+    this.splashColor,
18
+    this.disabledColor,
19
+    this.disabledTextColor,
20
+    this.onHighlightChanged,
21
+  }) : super(key: key);
22
+
23
+  // 渐变色数组
24
+  final List<Color>? colors;
25
+  final Color? textColor;
26
+  final Color? splashColor;
27
+  final Color? disabledTextColor;
28
+  final Color? disabledColor;
29
+  final EdgeInsetsGeometry? padding;
30
+  final Alignment? linearStart;
31
+  final Alignment? linearEnd;
32
+
33
+  final Widget child;
34
+  final BorderRadius? borderRadius;
35
+
36
+  final GestureTapCallback? onPressed;
37
+  final ValueChanged<bool>? onHighlightChanged;
38
+
39
+  @override
40
+  Widget build(BuildContext context) {
41
+    ThemeData theme = Theme.of(context);
42
+    //确保colors数组不空
43
+    List<Color> _colors =
44
+        colors ?? [theme.primaryColor, theme.primaryColorDark];
45
+    final radius = borderRadius;
46
+    bool disabled = onPressed == null;
47
+
48
+    return DecoratedBox(
49
+      decoration: BoxDecoration(
50
+        gradient: disabled ? null : LinearGradient(begin: linearStart??Alignment.topCenter, end: linearEnd??Alignment.bottomCenter, colors: _colors),
51
+        color: disabled ? disabledColor ?? theme.disabledColor : null,
52
+        borderRadius: radius,
53
+      ),
54
+      child: Material(
55
+        type: MaterialType.transparency,
56
+        borderRadius: radius,
57
+        clipBehavior: Clip.hardEdge,
58
+        child: ConstrainedBox(
59
+          constraints: const BoxConstraints(minWidth: 88.0, minHeight: 36.0),
60
+          child: InkWell(
61
+            splashColor: splashColor ?? _colors.last,
62
+            highlightColor: Colors.transparent,
63
+            onHighlightChanged: onHighlightChanged,
64
+            onTap: onPressed,
65
+            child: Padding(
66
+              padding: padding ?? theme.buttonTheme.padding,
67
+              child: DefaultTextStyle(
68
+                style: const TextStyle(fontWeight: FontWeight.bold),
69
+                child: Center(
70
+                  child: DefaultTextStyle(
71
+                    style: theme.textTheme.button!.copyWith(
72
+                      color: disabled
73
+                          ? disabledTextColor ?? Colors.black38
74
+                          : textColor ?? Colors.white,
75
+                    ),
76
+                    child: child,
77
+                  ),
78
+                  widthFactor: 1,
79
+                  heightFactor: 1,
80
+                ),
81
+              ),
82
+            ),
83
+          ),
84
+        ),
85
+      ),
86
+    );
87
+  }
88
+}

+ 48
- 48
pubspec.lock Ver arquivo

@@ -5,133 +5,133 @@ packages:
5 5
     dependency: transitive
6 6
     description:
7 7
       name: _fe_analyzer_shared
8
-      url: "https://pub.dartlang.org"
8
+      url: "https://pub.flutter-io.cn"
9 9
     source: hosted
10 10
     version: "38.0.0"
11 11
   analyzer:
12 12
     dependency: transitive
13 13
     description:
14 14
       name: analyzer
15
-      url: "https://pub.dartlang.org"
15
+      url: "https://pub.flutter-io.cn"
16 16
     source: hosted
17 17
     version: "3.4.1"
18 18
   args:
19 19
     dependency: transitive
20 20
     description:
21 21
       name: args
22
-      url: "https://pub.dartlang.org"
22
+      url: "https://pub.flutter-io.cn"
23 23
     source: hosted
24 24
     version: "2.3.0"
25 25
   async:
26 26
     dependency: transitive
27 27
     description:
28 28
       name: async
29
-      url: "https://pub.dartlang.org"
29
+      url: "https://pub.flutter-io.cn"
30 30
     source: hosted
31 31
     version: "2.8.2"
32 32
   boolean_selector:
33 33
     dependency: transitive
34 34
     description:
35 35
       name: boolean_selector
36
-      url: "https://pub.dartlang.org"
36
+      url: "https://pub.flutter-io.cn"
37 37
     source: hosted
38 38
     version: "2.1.0"
39 39
   build:
40 40
     dependency: transitive
41 41
     description:
42 42
       name: build
43
-      url: "https://pub.dartlang.org"
43
+      url: "https://pub.flutter-io.cn"
44 44
     source: hosted
45 45
     version: "2.2.1"
46 46
   build_config:
47 47
     dependency: transitive
48 48
     description:
49 49
       name: build_config
50
-      url: "https://pub.dartlang.org"
50
+      url: "https://pub.flutter-io.cn"
51 51
     source: hosted
52 52
     version: "1.0.0"
53 53
   characters:
54 54
     dependency: transitive
55 55
     description:
56 56
       name: characters
57
-      url: "https://pub.dartlang.org"
57
+      url: "https://pub.flutter-io.cn"
58 58
     source: hosted
59 59
     version: "1.2.0"
60 60
   charcode:
61 61
     dependency: transitive
62 62
     description:
63 63
       name: charcode
64
-      url: "https://pub.dartlang.org"
64
+      url: "https://pub.flutter-io.cn"
65 65
     source: hosted
66 66
     version: "1.3.1"
67 67
   checked_yaml:
68 68
     dependency: transitive
69 69
     description:
70 70
       name: checked_yaml
71
-      url: "https://pub.dartlang.org"
71
+      url: "https://pub.flutter-io.cn"
72 72
     source: hosted
73 73
     version: "2.0.1"
74 74
   clock:
75 75
     dependency: transitive
76 76
     description:
77 77
       name: clock
78
-      url: "https://pub.dartlang.org"
78
+      url: "https://pub.flutter-io.cn"
79 79
     source: hosted
80 80
     version: "1.1.0"
81 81
   collection:
82 82
     dependency: transitive
83 83
     description:
84 84
       name: collection
85
-      url: "https://pub.dartlang.org"
85
+      url: "https://pub.flutter-io.cn"
86 86
     source: hosted
87 87
     version: "1.15.0"
88 88
   convert:
89 89
     dependency: transitive
90 90
     description:
91 91
       name: convert
92
-      url: "https://pub.dartlang.org"
92
+      url: "https://pub.flutter-io.cn"
93 93
     source: hosted
94 94
     version: "3.0.1"
95 95
   crypto:
96 96
     dependency: transitive
97 97
     description:
98 98
       name: crypto
99
-      url: "https://pub.dartlang.org"
99
+      url: "https://pub.flutter-io.cn"
100 100
     source: hosted
101 101
     version: "3.0.1"
102 102
   cupertino_icons:
103 103
     dependency: "direct main"
104 104
     description:
105 105
       name: cupertino_icons
106
-      url: "https://pub.dartlang.org"
106
+      url: "https://pub.flutter-io.cn"
107 107
     source: hosted
108 108
     version: "1.0.4"
109 109
   dart_style:
110 110
     dependency: transitive
111 111
     description:
112 112
       name: dart_style
113
-      url: "https://pub.dartlang.org"
113
+      url: "https://pub.flutter-io.cn"
114 114
     source: hosted
115 115
     version: "2.2.2"
116 116
   dio:
117 117
     dependency: "direct main"
118 118
     description:
119 119
       name: dio
120
-      url: "https://pub.dartlang.org"
120
+      url: "https://pub.flutter-io.cn"
121 121
     source: hosted
122 122
     version: "4.0.6"
123 123
   fake_async:
124 124
     dependency: transitive
125 125
     description:
126 126
       name: fake_async
127
-      url: "https://pub.dartlang.org"
127
+      url: "https://pub.flutter-io.cn"
128 128
     source: hosted
129 129
     version: "1.2.0"
130 130
   file:
131 131
     dependency: transitive
132 132
     description:
133 133
       name: file
134
-      url: "https://pub.dartlang.org"
134
+      url: "https://pub.flutter-io.cn"
135 135
     source: hosted
136 136
     version: "6.1.2"
137 137
   flutter:
@@ -143,14 +143,14 @@ packages:
143 143
     dependency: "direct dev"
144 144
     description:
145 145
       name: flutter_lints
146
-      url: "https://pub.dartlang.org"
146
+      url: "https://pub.flutter-io.cn"
147 147
     source: hosted
148 148
     version: "1.0.4"
149 149
   flutter_screenutil:
150
-    dependency: "direct dev"
150
+    dependency: "direct main"
151 151
     description:
152 152
       name: flutter_screenutil
153
-      url: "https://pub.dartlang.org"
153
+      url: "https://pub.flutter-io.cn"
154 154
     source: hosted
155 155
     version: "5.3.1"
156 156
   flutter_test:
@@ -162,98 +162,98 @@ packages:
162 162
     dependency: "direct main"
163 163
     description:
164 164
       name: get
165
-      url: "https://pub.dartlang.org"
165
+      url: "https://pub.flutter-io.cn"
166 166
     source: hosted
167 167
     version: "4.6.1"
168 168
   glob:
169 169
     dependency: transitive
170 170
     description:
171 171
       name: glob
172
-      url: "https://pub.dartlang.org"
172
+      url: "https://pub.flutter-io.cn"
173 173
     source: hosted
174 174
     version: "2.0.2"
175 175
   http_parser:
176 176
     dependency: transitive
177 177
     description:
178 178
       name: http_parser
179
-      url: "https://pub.dartlang.org"
179
+      url: "https://pub.flutter-io.cn"
180 180
     source: hosted
181 181
     version: "4.0.0"
182 182
   json_annotation:
183 183
     dependency: transitive
184 184
     description:
185 185
       name: json_annotation
186
-      url: "https://pub.dartlang.org"
186
+      url: "https://pub.flutter-io.cn"
187 187
     source: hosted
188 188
     version: "4.4.0"
189 189
   json_serializable:
190 190
     dependency: "direct main"
191 191
     description:
192 192
       name: json_serializable
193
-      url: "https://pub.dartlang.org"
193
+      url: "https://pub.flutter-io.cn"
194 194
     source: hosted
195 195
     version: "6.1.5"
196 196
   lints:
197 197
     dependency: transitive
198 198
     description:
199 199
       name: lints
200
-      url: "https://pub.dartlang.org"
200
+      url: "https://pub.flutter-io.cn"
201 201
     source: hosted
202 202
     version: "1.0.1"
203 203
   logging:
204 204
     dependency: transitive
205 205
     description:
206 206
       name: logging
207
-      url: "https://pub.dartlang.org"
207
+      url: "https://pub.flutter-io.cn"
208 208
     source: hosted
209 209
     version: "1.0.2"
210 210
   matcher:
211 211
     dependency: transitive
212 212
     description:
213 213
       name: matcher
214
-      url: "https://pub.dartlang.org"
214
+      url: "https://pub.flutter-io.cn"
215 215
     source: hosted
216 216
     version: "0.12.11"
217 217
   material_color_utilities:
218 218
     dependency: transitive
219 219
     description:
220 220
       name: material_color_utilities
221
-      url: "https://pub.dartlang.org"
221
+      url: "https://pub.flutter-io.cn"
222 222
     source: hosted
223 223
     version: "0.1.3"
224 224
   meta:
225 225
     dependency: transitive
226 226
     description:
227 227
       name: meta
228
-      url: "https://pub.dartlang.org"
228
+      url: "https://pub.flutter-io.cn"
229 229
     source: hosted
230 230
     version: "1.7.0"
231 231
   package_config:
232 232
     dependency: transitive
233 233
     description:
234 234
       name: package_config
235
-      url: "https://pub.dartlang.org"
235
+      url: "https://pub.flutter-io.cn"
236 236
     source: hosted
237 237
     version: "2.0.2"
238 238
   path:
239 239
     dependency: transitive
240 240
     description:
241 241
       name: path
242
-      url: "https://pub.dartlang.org"
242
+      url: "https://pub.flutter-io.cn"
243 243
     source: hosted
244 244
     version: "1.8.0"
245 245
   pub_semver:
246 246
     dependency: transitive
247 247
     description:
248 248
       name: pub_semver
249
-      url: "https://pub.dartlang.org"
249
+      url: "https://pub.flutter-io.cn"
250 250
     source: hosted
251 251
     version: "2.1.1"
252 252
   pubspec_parse:
253 253
     dependency: transitive
254 254
     description:
255 255
       name: pubspec_parse
256
-      url: "https://pub.dartlang.org"
256
+      url: "https://pub.flutter-io.cn"
257 257
     source: hosted
258 258
     version: "1.2.0"
259 259
   sky_engine:
@@ -265,84 +265,84 @@ packages:
265 265
     dependency: transitive
266 266
     description:
267 267
       name: source_gen
268
-      url: "https://pub.dartlang.org"
268
+      url: "https://pub.flutter-io.cn"
269 269
     source: hosted
270 270
     version: "1.2.1"
271 271
   source_helper:
272 272
     dependency: transitive
273 273
     description:
274 274
       name: source_helper
275
-      url: "https://pub.dartlang.org"
275
+      url: "https://pub.flutter-io.cn"
276 276
     source: hosted
277 277
     version: "1.3.1"
278 278
   source_span:
279 279
     dependency: transitive
280 280
     description:
281 281
       name: source_span
282
-      url: "https://pub.dartlang.org"
282
+      url: "https://pub.flutter-io.cn"
283 283
     source: hosted
284 284
     version: "1.8.1"
285 285
   stack_trace:
286 286
     dependency: transitive
287 287
     description:
288 288
       name: stack_trace
289
-      url: "https://pub.dartlang.org"
289
+      url: "https://pub.flutter-io.cn"
290 290
     source: hosted
291 291
     version: "1.10.0"
292 292
   stream_channel:
293 293
     dependency: transitive
294 294
     description:
295 295
       name: stream_channel
296
-      url: "https://pub.dartlang.org"
296
+      url: "https://pub.flutter-io.cn"
297 297
     source: hosted
298 298
     version: "2.1.0"
299 299
   string_scanner:
300 300
     dependency: transitive
301 301
     description:
302 302
       name: string_scanner
303
-      url: "https://pub.dartlang.org"
303
+      url: "https://pub.flutter-io.cn"
304 304
     source: hosted
305 305
     version: "1.1.0"
306 306
   term_glyph:
307 307
     dependency: transitive
308 308
     description:
309 309
       name: term_glyph
310
-      url: "https://pub.dartlang.org"
310
+      url: "https://pub.flutter-io.cn"
311 311
     source: hosted
312 312
     version: "1.2.0"
313 313
   test_api:
314 314
     dependency: transitive
315 315
     description:
316 316
       name: test_api
317
-      url: "https://pub.dartlang.org"
317
+      url: "https://pub.flutter-io.cn"
318 318
     source: hosted
319 319
     version: "0.4.8"
320 320
   typed_data:
321 321
     dependency: transitive
322 322
     description:
323 323
       name: typed_data
324
-      url: "https://pub.dartlang.org"
324
+      url: "https://pub.flutter-io.cn"
325 325
     source: hosted
326 326
     version: "1.3.0"
327 327
   vector_math:
328 328
     dependency: transitive
329 329
     description:
330 330
       name: vector_math
331
-      url: "https://pub.dartlang.org"
331
+      url: "https://pub.flutter-io.cn"
332 332
     source: hosted
333 333
     version: "2.1.1"
334 334
   watcher:
335 335
     dependency: transitive
336 336
     description:
337 337
       name: watcher
338
-      url: "https://pub.dartlang.org"
338
+      url: "https://pub.flutter-io.cn"
339 339
     source: hosted
340 340
     version: "1.0.1"
341 341
   yaml:
342 342
     dependency: transitive
343 343
     description:
344 344
       name: yaml
345
-      url: "https://pub.dartlang.org"
345
+      url: "https://pub.flutter-io.cn"
346 346
     source: hosted
347 347
     version: "3.1.0"
348 348
 sdks:

+ 1
- 0
pubspec.yaml Ver arquivo

@@ -37,6 +37,7 @@ dependencies:
37 37
   json_serializable: ^6.1.5
38 38
   get: ^4.6.1
39 39
   dio: ^4.0.6
40
+  flutter_screenutil: ^5.3.1
40 41
 
41 42
 dev_dependencies:
42 43
   flutter_test: