|
@@ -6,6 +6,7 @@ import 'package:common_utils/common_utils.dart'; |
|
@@ -6,6 +6,7 @@ import 'package:common_utils/common_utils.dart'; |
|
6
|
import 'package:device_info/device_info.dart';
|
6
|
import 'package:device_info/device_info.dart';
|
|
7
|
import 'package:dio/dio.dart';
|
7
|
import 'package:dio/dio.dart';
|
|
8
|
import 'package:flutter/material.dart';
|
8
|
import 'package:flutter/material.dart';
|
|
|
|
9
|
+import 'package:flutter/services.dart';
|
|
9
|
import 'package:flutter_picker/Picker.dart';
|
10
|
import 'package:flutter_picker/Picker.dart';
|
|
10
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
11
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
11
|
import 'package:one_key/models/get_export_info_model.dart';
|
12
|
import 'package:one_key/models/get_export_info_model.dart';
|
|
@@ -28,11 +29,16 @@ import '../../../../utils/utils.dart'; |
|
@@ -28,11 +29,16 @@ import '../../../../utils/utils.dart'; |
|
28
|
import '../../../../widgets/h_empty_view.dart';
|
29
|
import '../../../../widgets/h_empty_view.dart';
|
|
29
|
// import 'package:flutter_downloader/flutter_downloader.dart';
|
30
|
// import 'package:flutter_downloader/flutter_downloader.dart';
|
|
30
|
// import 'package:android_path_provider/android_path_provider.dart';
|
31
|
// import 'package:android_path_provider/android_path_provider.dart';
|
|
31
|
-import 'package:open_file/open_file.dart';
|
32
|
+// import 'package:open_file/open_file.dart';
|
|
|
|
33
|
+import 'package:open_filex/open_filex.dart';
|
|
32
|
import 'package:excel/excel.dart' as excelUtil;
|
34
|
import 'package:excel/excel.dart' as excelUtil;
|
|
33
|
|
35
|
|
|
34
|
import '../../../../widgets/loading.dart';
|
36
|
import '../../../../widgets/loading.dart';
|
|
35
|
|
37
|
|
|
|
|
38
|
+import 'package:external_path/external_path.dart';
|
|
|
|
39
|
+// import 'package:open_file_plus/open_file_plus.dart';
|
|
|
|
40
|
+// import 'package:flutter_filereader/flutter_filereader.dart';
|
|
|
|
41
|
+
|
|
36
|
/**
|
42
|
/**
|
|
37
|
* 导出预订数据
|
43
|
* 导出预订数据
|
|
38
|
*/
|
44
|
*/
|
|
@@ -52,17 +58,14 @@ class _ExportBookDataPageState extends State<ExportBookDataPage> { |
|
@@ -52,17 +58,14 @@ class _ExportBookDataPageState extends State<ExportBookDataPage> { |
|
52
|
|
58
|
|
|
53
|
List<String> data = ['到店时间', '下单时间'];
|
59
|
List<String> data = ['到店时间', '下单时间'];
|
|
54
|
int timeIndex;
|
60
|
int timeIndex;
|
|
55
|
- // ReceivePort _port = ReceivePort();
|
61
|
+
|
|
56
|
String _localPath;
|
62
|
String _localPath;
|
|
57
|
|
63
|
|
|
58
|
String taskId;
|
64
|
String taskId;
|
|
59
|
- // DownloadTaskStatus status;
|
|
|
|
60
|
int progress;
|
65
|
int progress;
|
|
61
|
|
66
|
|
|
62
|
CustomerProvider customerProvider;
|
67
|
CustomerProvider customerProvider;
|
|
63
|
|
68
|
|
|
64
|
- // List<Map<String, String>> fieldData = {};
|
|
|
|
65
|
-
|
|
|
|
66
|
@override
|
69
|
@override
|
|
67
|
void initState() {
|
70
|
void initState() {
|
|
68
|
super.initState();
|
71
|
super.initState();
|
|
@@ -73,12 +76,9 @@ class _ExportBookDataPageState extends State<ExportBookDataPage> { |
|
@@ -73,12 +76,9 @@ class _ExportBookDataPageState extends State<ExportBookDataPage> { |
|
73
|
}
|
76
|
}
|
|
74
|
|
77
|
|
|
75
|
_getReportField() async {
|
78
|
_getReportField() async {
|
|
76
|
- bool success = await customerProvider.getReportField(context);
|
|
|
|
77
|
- // if (success) {
|
|
|
|
78
|
- // customerProvider.reportFieldModelData.forEach((element) {
|
|
|
|
79
|
- // fieldData[element.code] = element.name;
|
|
|
|
80
|
- // });
|
|
|
|
81
|
- // }
|
79
|
+ await customerProvider.getReportField(context);
|
|
|
|
80
|
+
|
|
|
|
81
|
+ await _checkPermission();
|
|
82
|
}
|
82
|
}
|
|
83
|
|
83
|
|
|
84
|
Future<void> _prepareSaveDir() async {
|
84
|
Future<void> _prepareSaveDir() async {
|
|
@@ -93,23 +93,9 @@ class _ExportBookDataPageState extends State<ExportBookDataPage> { |
|
@@ -93,23 +93,9 @@ class _ExportBookDataPageState extends State<ExportBookDataPage> { |
|
93
|
String externalStorageDirPath;
|
93
|
String externalStorageDirPath;
|
|
94
|
|
94
|
|
|
95
|
if (Platform.isAndroid) {
|
95
|
if (Platform.isAndroid) {
|
|
96
|
- // try {
|
|
|
|
97
|
- // externalStorageDirPath = await AndroidPathProvider.downloadsPath;
|
|
|
|
98
|
- // } catch (err, st) {
|
|
|
|
99
|
- // print('failed to get downloads path: $err, $st');
|
|
|
|
100
|
-
|
|
|
|
101
|
- // if()/
|
|
|
|
102
|
-
|
|
|
|
103
|
- // final directory = await getExternalStorageDirectory();
|
|
|
|
104
|
- // externalStorageDirPath = directory?.path;
|
|
|
|
105
|
-
|
|
|
|
106
|
- externalStorageDirPath = '/storage/emulated/0/Download';
|
96
|
+ final directory = await getExternalStorageDirectory();
|
|
|
|
97
|
+ externalStorageDirPath = directory?.path;
|
|
107
|
} else if (Platform.isIOS) {
|
98
|
} else if (Platform.isIOS) {
|
|
108
|
- // externalStorageDirPath =
|
|
|
|
109
|
- // (await getApplicationDocumentsDirectory()).absolute.path;
|
|
|
|
110
|
-
|
|
|
|
111
|
- // externalStorageDirPath = (await getTemporaryDirectory()).path;
|
|
|
|
112
|
-
|
|
|
|
113
|
externalStorageDirPath = (await getApplicationSupportDirectory()).path;
|
99
|
externalStorageDirPath = (await getApplicationSupportDirectory()).path;
|
|
114
|
|
100
|
|
|
115
|
externalStorageDirPath =
|
101
|
externalStorageDirPath =
|
|
@@ -124,38 +110,42 @@ class _ExportBookDataPageState extends State<ExportBookDataPage> { |
|
@@ -124,38 +110,42 @@ class _ExportBookDataPageState extends State<ExportBookDataPage> { |
|
124
|
}
|
110
|
}
|
|
125
|
|
111
|
|
|
126
|
if (Platform.isAndroid) {
|
112
|
if (Platform.isAndroid) {
|
|
127
|
- // final info = await DeviceInfoPlugin().androidInfo;
|
|
|
|
128
|
- // if (info.version.sdkInt > 28) {
|
|
|
|
129
|
- // return true;
|
|
|
|
130
|
- // }
|
|
|
|
131
|
-
|
|
|
|
132
|
- final status = await Permission.manageExternalStorage.status;
|
|
|
|
133
|
- if (status == PermissionStatus.granted) {
|
|
|
|
134
|
- return true;
|
|
|
|
135
|
- }
|
113
|
+ final info = await DeviceInfoPlugin().androidInfo;
|
|
136
|
|
114
|
|
|
137
|
- if (Platform.isAndroid) {
|
|
|
|
138
|
- // try {
|
|
|
|
139
|
- // externalStorageDirPath = await AndroidPathProvider.downloadsPath;
|
|
|
|
140
|
- // } catch (err, st) {
|
|
|
|
141
|
- // print('failed to get downloads path: $err, $st');
|
115
|
+ if (info.version.sdkInt >= 33) {
|
|
|
|
116
|
+ final status = await Permission.photos.status;
|
|
|
|
117
|
+ if (status == PermissionStatus.granted) {
|
|
|
|
118
|
+ return true;
|
|
|
|
119
|
+ }
|
|
|
|
120
|
+
|
|
|
|
121
|
+ if (status != PermissionStatus.permanentlyDenied) {
|
|
|
|
122
|
+//全局提示权限使用目的
|
|
|
|
123
|
+ BuildContext context = App.navigatorKey.currentState.overlay.context;
|
|
|
|
124
|
+ dynamic object = DialogUtil.showAuthorityDestination(
|
|
|
|
125
|
+ context, 'h_storage', '访问照片和视频权限', '用于存储下载的预订表。');
|
|
|
|
126
|
+ print(object);
|
|
|
|
127
|
+ }
|
|
142
|
|
128
|
|
|
143
|
- // if()/
|
|
|
|
144
|
- PermissionStatus permissionStatus =
|
|
|
|
145
|
- await Permission.manageExternalStorage.status;
|
129
|
+ final result = await Permission.photos.request();
|
|
|
|
130
|
+ return result == PermissionStatus.granted;
|
|
|
|
131
|
+ } else {
|
|
|
|
132
|
+ final status = await Permission.storage.status;
|
|
|
|
133
|
+ if (status == PermissionStatus.granted) {
|
|
|
|
134
|
+ return true;
|
|
|
|
135
|
+ }
|
|
146
|
|
136
|
|
|
147
|
- if (permissionStatus != PermissionStatus.permanentlyDenied) {
|
137
|
+ if (status != PermissionStatus.permanentlyDenied) {
|
|
148
|
//全局提示权限使用目的
|
138
|
//全局提示权限使用目的
|
|
149
|
BuildContext context = App.navigatorKey.currentState.overlay.context;
|
139
|
BuildContext context = App.navigatorKey.currentState.overlay.context;
|
|
150
|
DialogUtil.showAuthorityDestination(
|
140
|
DialogUtil.showAuthorityDestination(
|
|
151
|
- context, 'h_storage', '访问所有文件权限', '用于存储下载的预订表。');
|
141
|
+ context, 'h_storage', '访问存储权限', '用于存储下载的预订表。');
|
|
152
|
}
|
142
|
}
|
|
153
|
- }
|
|
|
|
154
|
|
143
|
|
|
155
|
- final result = await Permission.manageExternalStorage.request();
|
|
|
|
156
|
- return result == PermissionStatus.granted;
|
144
|
+ final result = await Permission.storage.request();
|
|
|
|
145
|
+ return result == PermissionStatus.granted;
|
|
|
|
146
|
+ }
|
|
157
|
}
|
147
|
}
|
|
158
|
-
|
148
|
+ // manageExternalStorage
|
|
159
|
throw StateError('unknown platform');
|
149
|
throw StateError('unknown platform');
|
|
160
|
}
|
150
|
}
|
|
161
|
|
151
|
|
|
@@ -338,25 +328,29 @@ class _ExportBookDataPageState extends State<ExportBookDataPage> { |
|
@@ -338,25 +328,29 @@ class _ExportBookDataPageState extends State<ExportBookDataPage> { |
|
338
|
Provider.of<UserModel>(context, listen: false).user.sellername;
|
328
|
Provider.of<UserModel>(context, listen: false).user.sellername;
|
|
339
|
String starttime = fromDate.replaceAll('-', '');
|
329
|
String starttime = fromDate.replaceAll('-', '');
|
|
340
|
String endtime = endDate.replaceAll('-', '');
|
330
|
String endtime = endDate.replaceAll('-', '');
|
|
341
|
- String fileName = "/${sellername}${starttime}至${endtime}.xlsx";
|
331
|
+ String nameS = '/${sellername}${starttime}至${endtime}_';
|
|
|
|
332
|
+ String timetemp =
|
|
|
|
333
|
+ ((DateTime.now().millisecondsSinceEpoch / 1000).floor()).toString();
|
|
|
|
334
|
+ String sunfix = '.xlsx';
|
|
|
|
335
|
+
|
|
|
|
336
|
+ // String sunfix = '.xls';
|
|
|
|
337
|
+ // String fileName = "/${sellername}${starttime}至${endtime}.xlsx";
|
|
|
|
338
|
+ String fileName = nameS + timetemp + sunfix;
|
|
|
|
339
|
+ if (Platform.isIOS) {
|
|
|
|
340
|
+ fileName = nameS + sunfix;
|
|
|
|
341
|
+ }
|
|
342
|
String filePath = _localPath + '${fileName}';
|
342
|
String filePath = _localPath + '${fileName}';
|
|
343
|
- // Utils.showToast('文件已保存到${filePath}');
|
343
|
+
|
|
344
|
if (fileBytes != null) {
|
344
|
if (fileBytes != null) {
|
|
345
|
- // File file =
|
|
|
|
346
|
- File(filePath)
|
345
|
+ File file = File(filePath)
|
|
347
|
..createSync(recursive: true)
|
346
|
..createSync(recursive: true)
|
|
348
|
..writeAsBytesSync(fileBytes);
|
347
|
..writeAsBytesSync(fileBytes);
|
|
349
|
- // try {
|
|
|
|
350
|
- // // File file1 = File('/storage/emulated/0/Download${fileName}')
|
|
|
|
351
|
- // // ..createSync(recursive: true)
|
|
|
|
352
|
- // // ..writeAsBytesSync(fileBytes);
|
|
|
|
353
|
- // // File file2 =
|
|
|
|
354
|
- // // await file.copy('/storage/emulated/0/Documents${fileName}');
|
|
|
|
355
|
- // File file1 = await file.copy('/storage/emulated/0/Download${fileName}');
|
|
|
|
356
|
- // Utils.showToast('文件已保存到${file1.path}');
|
|
|
|
357
|
- // } catch (e) {
|
|
|
|
358
|
- // Utils.showToast('保存失败:${e}');
|
|
|
|
359
|
- // }
|
348
|
+ try {
|
|
|
|
349
|
+ File file1 = await file.copy('/storage/emulated/0/Download${fileName}');
|
|
|
|
350
|
+ // Utils.showToast('文件已保存到${file1.path}');
|
|
|
|
351
|
+ } catch (e) {
|
|
|
|
352
|
+ // Utils.showToast('保存失败!');
|
|
|
|
353
|
+ }
|
|
360
|
|
354
|
|
|
361
|
Loading.hideLoading(context);
|
355
|
Loading.hideLoading(context);
|
|
362
|
DialogUtil.cupertinoAlertDialog(context,
|
356
|
DialogUtil.cupertinoAlertDialog(context,
|
|
@@ -369,24 +363,21 @@ class _ExportBookDataPageState extends State<ExportBookDataPage> { |
|
@@ -369,24 +363,21 @@ class _ExportBookDataPageState extends State<ExportBookDataPage> { |
|
369
|
progress = null;
|
363
|
progress = null;
|
|
370
|
setState(() {});
|
364
|
setState(() {});
|
|
371
|
}, rCallback: () async {
|
365
|
}, rCallback: () async {
|
|
372
|
- // Navigator.pop(context);
|
|
|
|
373
|
-
|
|
|
|
374
|
- // print(_localPath);
|
|
|
|
375
|
-
|
|
|
|
376
|
- // final tasks = await FlutterDownloader.loadTasks();
|
|
|
|
377
|
- // String str = '';
|
|
|
|
378
|
- // tasks.forEach((element) {
|
|
|
|
379
|
- // str = element.savedDir + '/' + element.filename;
|
|
|
|
380
|
- // });
|
|
|
|
381
|
- // print(str);
|
|
|
|
382
|
-
|
|
|
|
383
|
- // if (str != '') {
|
|
|
|
384
|
- // print(savePath);
|
|
|
|
385
|
- // progress = null;
|
|
|
|
386
|
- // setState(() {});
|
|
|
|
387
|
- OpenFile.open(filePath);
|
|
|
|
388
|
- // _delete();
|
|
|
|
389
|
- // }
|
366
|
+ // final result =
|
|
|
|
367
|
+ // await OpenFilex.open(filePath, type: 'application/vnd.ms-excel');
|
|
|
|
368
|
+ final result = await OpenFilex.open(filePath,
|
|
|
|
369
|
+ type:
|
|
|
|
370
|
+ 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
|
|
|
|
371
|
+ print(result.type);
|
|
|
|
372
|
+ if (result.type == ResultType.noAppToOpen) {
|
|
|
|
373
|
+ Utils.showToast('没有应用可以打开');
|
|
|
|
374
|
+ } else if (result.type == ResultType.fileNotFound) {
|
|
|
|
375
|
+ Utils.showToast('找不到文件');
|
|
|
|
376
|
+ } else if (result.type == ResultType.permissionDenied) {
|
|
|
|
377
|
+ Utils.showToast('没有相关权限');
|
|
|
|
378
|
+ } else if (result.type == ResultType.permissionDenied) {
|
|
|
|
379
|
+ Utils.showToast('发生未知错误');
|
|
|
|
380
|
+ }
|
|
390
|
});
|
381
|
});
|
|
391
|
} else {
|
382
|
} else {
|
|
392
|
Loading.hideLoading(context);
|
383
|
Loading.hideLoading(context);
|
|
@@ -412,13 +403,6 @@ class _ExportBookDataPageState extends State<ExportBookDataPage> { |
|
@@ -412,13 +403,6 @@ class _ExportBookDataPageState extends State<ExportBookDataPage> { |
|
412
|
// controller: controller,
|
403
|
// controller: controller,
|
|
413
|
child: Column(
|
404
|
child: Column(
|
|
414
|
children: [
|
405
|
children: [
|
|
415
|
- // (status == DownloadTaskStatus.running ||
|
|
|
|
416
|
- // status == DownloadTaskStatus.paused)
|
|
|
|
417
|
- // ? LinearProgressIndicator(
|
|
|
|
418
|
- // value: progress / 100,
|
|
|
|
419
|
- // )
|
|
|
|
420
|
- // : VEmptyView(10),
|
|
|
|
421
|
-
|
|
|
|
422
|
progress != null && progress != 100
|
406
|
progress != null && progress != 100
|
|
423
|
? LinearProgressIndicator(
|
407
|
? LinearProgressIndicator(
|
|
424
|
value: progress / 100,
|
408
|
value: progress / 100,
|
|
@@ -604,7 +588,12 @@ class _ExportBookDataPageState extends State<ExportBookDataPage> { |
|
@@ -604,7 +588,12 @@ class _ExportBookDataPageState extends State<ExportBookDataPage> { |
|
604
|
await customerProvider.getExportInfo(context, pramas);
|
588
|
await customerProvider.getExportInfo(context, pramas);
|
|
605
|
if (success) {
|
589
|
if (success) {
|
|
606
|
//成功
|
590
|
//成功
|
|
607
|
- _download();
|
591
|
+ if (customerProvider.exportInfoSunModel.list.length == 0) {
|
|
|
|
592
|
+ Utils.showToast('当前时间段内没有预订数据!');
|
|
|
|
593
|
+ return;
|
|
|
|
594
|
+ } else {
|
|
|
|
595
|
+ _download();
|
|
|
|
596
|
+ }
|
|
608
|
}
|
597
|
}
|
|
609
|
} else {
|
598
|
} else {
|
|
610
|
// String title = Platform.isAndroid ? '存储' : '相册';
|
599
|
// String title = Platform.isAndroid ? '存储' : '相册';
|