Browse Source

修复获取个人信息异常问题; 修改底部导航栏颜色; 保存二维码增加单号;

maqiang 11 months ago
parent
commit
2aa3716773

+ 7 - 1
lib/base/base_state.dart

@@ -1,5 +1,6 @@
1 1
 import 'package:flutter/material.dart';
2 2
 import 'package:flutter/services.dart';
3
+import 'package:lszlgl/config/colors.dart';
3 4
 import 'package:lszlgl/config/pics.dart';
4 5
 
5 6
 export 'package:lszlgl/config/pics.dart';
@@ -27,6 +28,8 @@ abstract class BaseState<T extends StatefulWidget> extends State<T> {
27 28
     PreferredSizeWidget? bottom,
28 29
     double? toolbarHeight,
29 30
     List<Widget>? actions,
31
+    Color? naviBarColor,
32
+    Brightness? naviBarBrightness,
30 33
   }) {
31 34
     return AppBar(
32 35
       title: Text(title),
@@ -34,7 +37,10 @@ abstract class BaseState<T extends StatefulWidget> extends State<T> {
34 37
       automaticallyImplyLeading: autoLeading,
35 38
       toolbarHeight: toolbarHeight,
36 39
       actions: actions,
37
-      systemOverlayStyle: SystemUiOverlayStyle.light.copyWith(systemNavigationBarColor: Colors.transparent),
40
+      systemOverlayStyle: SystemUiOverlayStyle.light.copyWith(
41
+        systemNavigationBarColor: naviBarColor ?? MyColor.c_background,
42
+        systemNavigationBarIconBrightness: naviBarBrightness ?? Brightness.dark,
43
+      ),
38 44
     );
39 45
   }
40 46
 

+ 1 - 0
lib/config/colors.dart

@@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
3 3
 class MyColor {
4 4
   MyColor._();
5 5
 
6
+  static const Color c_background = Color(0xFFF5F5F5);
6 7
   static const Color c_333333 = Color(0xFF333333);
7 8
   static const Color c_666666 = Color(0xFF666666);
8 9
 

+ 2 - 6
lib/main.dart

@@ -1,11 +1,10 @@
1 1
 import 'dart:async';
2
-import 'dart:io';
3
-
4 2
 import 'package:flutter/material.dart';
5 3
 import 'package:flutter/services.dart';
6 4
 import 'package:flutter_localizations/flutter_localizations.dart';
7 5
 import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
8 6
 import 'package:logger/logger.dart';
7
+import 'package:lszlgl/config/colors.dart';
9 8
 import 'package:lszlgl/router/my_navigator.dart';
10 9
 
11 10
 late Logger logger;
@@ -14,9 +13,6 @@ void main() async {
14 13
   logger = Logger(printer: PrettyPrinter(methodCount: 0));
15 14
   initReportException(() async {
16 15
     SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle.light.copyWith(statusBarColor: Colors.transparent));
17
-    if (Platform.isAndroid) {
18
-      await SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge);
19
-    }
20 16
     SystemChrome.setPreferredOrientations([
21 17
       DeviceOrientation.portraitUp,
22 18
       DeviceOrientation.portraitDown,
@@ -65,7 +61,7 @@ class MyApp extends StatelessWidget {
65 61
         colorScheme: ColorScheme.fromSeed(
66 62
           seedColor: Colors.blue,
67 63
         ),
68
-        scaffoldBackgroundColor: const Color(0xFFF5F5F5),
64
+        scaffoldBackgroundColor: MyColor.c_background,
69 65
         // navigationBarTheme: const NavigationBarThemeData(height: 56),
70 66
         appBarTheme: const AppBarTheme(
71 67
           centerTitle: true,

+ 1 - 1
lib/model/rsp/user_rsp.dart

@@ -85,7 +85,7 @@ class UserRsp {
85 85
 
86 86
 @JsonSerializable()
87 87
 class DepartmentRsp {
88
-  final num? id;
88
+  final String? id;
89 89
   final String? name;
90 90
   final num? parentId;
91 91
 

+ 1 - 1
lib/model/rsp/user_rsp.g.dart

@@ -46,7 +46,7 @@ Map<String, dynamic> _$UserRspToJson(UserRsp instance) => <String, dynamic>{
46 46
 
47 47
 DepartmentRsp _$DepartmentRspFromJson(Map<String, dynamic> json) =>
48 48
     DepartmentRsp(
49
-      id: json['id'] as num?,
49
+      id: json['id'] as String?,
50 50
       name: json['name'] as String?,
51 51
       parentId: json['parentId'] as num?,
52 52
     );

+ 5 - 1
lib/page/home/home_page.dart

@@ -42,7 +42,11 @@ class _HomePageState extends BaseState<HomePage> with AutomaticKeepAliveClientMi
42 42
   Widget buildBody() {
43 43
     return Column(
44 44
       children: [
45
-        myAppBar(title: '质量安全检验监测', autoLeading: false),
45
+        myAppBar(
46
+          title: '质量安全检验监测',
47
+          autoLeading: false,
48
+          naviBarColor: Colors.white,
49
+        ),
46 50
         Expanded(
47 51
           child: SingleChildScrollView(
48 52
             physics: const BouncingScrollPhysics(),

+ 8 - 3
lib/page/login/login_page.dart

@@ -40,8 +40,10 @@ class _LoginPageState extends BaseLifecycleState<LoginPage> {
40 40
       await UserService.get().saveLogin(login.data);
41 41
       getSystemData();
42 42
     } on DioException catch (_) {
43
-      MyNavigator.dismissLoading();
43
+    } catch (_) {
44
+      MyNavigator.showToast('获取数据失败');
44 45
     }
46
+    MyNavigator.dismissLoading();
45 47
   }
46 48
 
47 49
   /// 获取基础数据
@@ -59,9 +61,10 @@ class _LoginPageState extends BaseLifecycleState<LoginPage> {
59 61
       MyNavigator.dismissLoading();
60 62
       startHome();
61 63
     } on DioException catch (_) {
62
-      // 获取数据失败
63
-      MyNavigator.dismissLoading();
64
+    } catch (_) {
65
+      MyNavigator.showToast('获取数据失败');
64 66
     }
67
+    MyNavigator.dismissLoading();
65 68
   }
66 69
 
67 70
   /// 进入主页
@@ -78,6 +81,7 @@ class _LoginPageState extends BaseLifecycleState<LoginPage> {
78 81
   @override
79 82
   void onFirstShow(Duration timeStamp) async {
80 83
     MyNavigator.showLoading();
84
+
81 85
     /// 初始化基础库 start
82 86
     BaseDio.get().init();
83 87
     await SPUtils.getInstance().init();
@@ -85,6 +89,7 @@ class _LoginPageState extends BaseLifecycleState<LoginPage> {
85 89
     LocationUtils.updatePrivacyShow(true, true);
86 90
     LocationUtils.updatePrivacyAgree(true);
87 91
     LocationUtils.setApiKey('2c783509376e267b24d63b21681686fa', '');
92
+
88 93
     /// 初始化基础库 end
89 94
     MyNavigator.dismissLoading();
90 95
     // 已登录

+ 1 - 0
lib/page/main_tab_page.dart

@@ -94,6 +94,7 @@ class _MainTabPageState extends State<MainTabPage> {
94 94
       selectedIndex: selectedIndex,
95 95
       surfaceTintColor: Colors.white,
96 96
       onDestinationSelected: (index) => refreshTab(index, refreshPage: true),
97
+      backgroundColor: Colors.white,
97 98
       destinations: List.generate(
98 99
         tabTextList.length,
99 100
         (index) => GestureDetector(

+ 40 - 25
lib/page/sample_task/reap_sample_detail/reap_sample_task_page.dart

@@ -2,7 +2,6 @@ import 'dart:io';
2 2
 import 'dart:typed_data';
3 3
 
4 4
 import 'package:cached_network_image/cached_network_image.dart';
5
-import 'package:dio/dio.dart';
6 5
 import 'package:flutter/material.dart';
7 6
 import 'package:flutter_keyboard_visibility/flutter_keyboard_visibility.dart';
8 7
 import 'package:image_gallery_saver/image_gallery_saver.dart';
@@ -144,6 +143,8 @@ class _ReapSampleTaskPageState extends BaseLifecycleState<ReapSampleTaskPage> wi
144 143
     ];
145 144
   }
146 145
 
146
+  GlobalKey ewmKey = GlobalKey();
147
+
147 148
   /// 查看二维码
148 149
   void startQRCode() {
149 150
     UrlItem picInfo = pageStatus.value.data!.ewmfilePictureList!.first;
@@ -158,25 +159,35 @@ class _ReapSampleTaskPageState extends BaseLifecycleState<ReapSampleTaskPage> wi
158 159
         child: Column(
159 160
           mainAxisSize: MainAxisSize.min,
160 161
           children: [
161
-            CachedNetworkImage(
162
-              width: double.infinity,
163
-              fit: BoxFit.cover,
164
-              imageUrl: picInfo.url!,
165
-              placeholder: (_, __) => const Center(child: CircularProgressIndicator()),
166
-              errorWidget: (context, url, error) => const Center(child: Icon(Icons.error)),
167
-            ),
168
-            Padding(
169
-              padding: const EdgeInsets.symmetric(vertical: 16),
170
-              child: Text(
171
-                picInfo.name ?? '',
172
-                style: const TextStyle(fontSize: 16, color: MyColor.c_333333),
162
+            RepaintBoundary(
163
+              key: ewmKey,
164
+              child: Container(
165
+                color: Colors.white,
166
+                child: Column(
167
+                  children: [
168
+                    CachedNetworkImage(
169
+                      width: double.infinity,
170
+                      fit: BoxFit.cover,
171
+                      imageUrl: picInfo.url!,
172
+                      placeholder: (_, __) => const Center(child: CircularProgressIndicator()),
173
+                      errorWidget: (context, url, error) => const Center(child: Icon(Icons.error)),
174
+                    ),
175
+                    Padding(
176
+                      padding: const EdgeInsets.symmetric(vertical: 16),
177
+                      child: Text(
178
+                        picInfo.name ?? '',
179
+                        style: const TextStyle(fontSize: 18, color: MyColor.c_333333),
180
+                      ),
181
+                    ),
182
+                  ],
183
+                ),
173 184
               ),
174 185
             ),
175 186
             Row(
176 187
               children: [
177 188
                 const Expanded(child: MyButton('打印')),
178 189
                 const SizedBox(width: 16),
179
-                Expanded(child: MyButton('保存图片', onTap: savePic)),
190
+                Expanded(child: MyButton('保存图片', onTap: () => savePic(picInfo.name))),
180 191
               ],
181 192
             ),
182 193
           ],
@@ -185,12 +196,15 @@ class _ReapSampleTaskPageState extends BaseLifecycleState<ReapSampleTaskPage> wi
185 196
     );
186 197
   }
187 198
 
188
-  void savePic() async {
199
+  void savePic(String? name) async {
189 200
     MyNavigator.showLoading(msg: '保存中...');
190
-    var response = await Dio().get(
191
-        'https://gd-hbimg.huaban.com/c7a22fb15d70a0a976e20fb810c048ec11c76fc31ac08-hajElf_fw658webp',
192
-        options: Options(responseType: ResponseType.bytes));
193
-    final result = await ImageGallerySaver.saveImage(Uint8List.fromList(response.data), quality: 60, name: "hello");
201
+    Uint8List? bytes = await FileUtils.getBitmapFromContext(ewmKey.currentContext);
202
+    if (bytes == null) {
203
+      MyNavigator.dismiss();
204
+      MyNavigator.showToast('保存失败');
205
+      return;
206
+    }
207
+    final result = await ImageGallerySaver.saveImage(bytes, quality: 60, name: name);
194 208
     MyNavigator.dismiss();
195 209
     if (result['isSuccess']) {
196 210
       MyNavigator.showToast('保存成功');
@@ -338,13 +352,14 @@ class _ReapSampleTaskPageState extends BaseLifecycleState<ReapSampleTaskPage> wi
338 352
 
339 353
   Widget buildButton() {
340 354
     Widget child;
341
-    EdgeInsets margin = EdgeInsets.only(left: 16, right: 16, top: 12, bottom: getBottomPadding(12));
355
+    EdgeInsets margin = EdgeInsets.only(left: 8, right: 8, top: 12, bottom: getBottomPadding(12));
356
+    Widget ewmWidget = (pageStatus.value.data?.ewmfilePictureList ?? []).isEmpty
357
+        ? const SizedBox.shrink()
358
+        : Expanded(child: MyButton('查看二维码', onTap: startQRCode, margin: margin));
342 359
     if (args.detail) {
343 360
       child = Row(
344 361
         children: [
345
-          (pageStatus.value.data?.ewmfilePictureList ?? []).isEmpty
346
-              ? const SizedBox.shrink()
347
-              : Expanded(child: MyButton('查看二维码', onTap: startQRCode, margin: margin)),
362
+          ewmWidget,
348 363
           Expanded(child: MyButton('重新录入', onTap: startEdit, margin: margin)),
349 364
         ],
350 365
       );
@@ -357,7 +372,7 @@ class _ReapSampleTaskPageState extends BaseLifecycleState<ReapSampleTaskPage> wi
357 372
           return Row(
358 373
             children: [
359 374
               Expanded(child: MyButton('上一步', onTap: previous, margin: margin)),
360
-              const SizedBox(width: 32),
375
+              ewmWidget,
361 376
               Expanded(child: MyButton('提交', onTap: submit, margin: margin)),
362 377
             ],
363 378
           );
@@ -365,7 +380,6 @@ class _ReapSampleTaskPageState extends BaseLifecycleState<ReapSampleTaskPage> wi
365 380
         return Row(
366 381
           children: [
367 382
             Expanded(child: MyButton('上一步', onTap: previous, margin: margin)),
368
-            const SizedBox(width: 32),
369 383
             Expanded(child: MyButton('下一步', onTap: next, margin: margin)),
370 384
           ],
371 385
         );
@@ -373,6 +387,7 @@ class _ReapSampleTaskPageState extends BaseLifecycleState<ReapSampleTaskPage> wi
373 387
     }
374 388
     return Container(
375 389
       color: const Color(0xFFF1F7F6),
390
+      padding: const EdgeInsets.symmetric(horizontal: 8),
376 391
       child: child,
377 392
     );
378 393
   }

+ 1 - 0
lib/page/sample_task/sample_task_list_tab_page.dart

@@ -105,6 +105,7 @@ class _SampleTaskListTabPageState extends BaseLifecycleState<SampleTaskListTabPa
105 105
         myAppBar(
106 106
           title: widget.args.type.title,
107 107
           actions: [buildFilter()],
108
+          naviBarColor: Colors.white,
108 109
         ),
109 110
         buildTab(),
110 111
         const SizedBox(height: 12),

+ 5 - 1
lib/page/user_center/user_center_page.dart

@@ -49,7 +49,11 @@ class _UserCenterPageState extends BaseLifecycleState<UserCenterPage> with Autom
49 49
   Widget buildBody() {
50 50
     return Column(
51 51
       children: [
52
-        myAppBar(title: '用户中心', autoLeading: false),
52
+        myAppBar(
53
+          title: '用户中心',
54
+          autoLeading: false,
55
+          naviBarColor: Colors.white,
56
+        ),
53 57
         Expanded(
54 58
           child: EasyRefresh(
55 59
             onRefresh: onRefresh,

+ 15 - 0
lib/utils/file_utils.dart

@@ -1,6 +1,9 @@
1 1
 import 'dart:io';
2 2
 import 'dart:typed_data';
3
+import 'dart:ui' as ui;
3 4
 
5
+import 'package:flutter/cupertino.dart';
6
+import 'package:flutter/rendering.dart';
4 7
 import 'package:path_provider/path_provider.dart';
5 8
 
6 9
 class FileUtils {
@@ -11,4 +14,16 @@ class FileUtils {
11 14
     await file.writeAsBytes(data);
12 15
     return file;
13 16
   }
17
+
18
+  /// 从Context中获取图片
19
+  static Future<Uint8List?> getBitmapFromContext(
20
+    BuildContext? context, {
21
+    double pixelRatio = 3.0,
22
+  }) async {
23
+    if (context == null) return null;
24
+    RenderRepaintBoundary render = context.findRenderObject() as RenderRepaintBoundary;
25
+    ui.Image image = await render.toImage(pixelRatio: pixelRatio);
26
+    ByteData? bytes = await image.toByteData(format: ui.ImageByteFormat.png);
27
+    return bytes?.buffer.asUint8List();
28
+  }
14 29
 }