|
@@ -4,6 +4,7 @@ import 'dart:ui'; |
|
@@ -4,6 +4,7 @@ import 'dart:ui'; |
|
4
|
|
4
|
|
|
5
|
import 'package:common_utils/common_utils.dart';
|
5
|
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:flutter/material.dart';
|
8
|
import 'package:flutter/material.dart';
|
|
8
|
import 'package:flutter_picker/Picker.dart';
|
9
|
import 'package:flutter_picker/Picker.dart';
|
|
9
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
10
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
@@ -14,12 +15,14 @@ import 'package:one_key/widgets/v_empty_view.dart'; |
|
@@ -14,12 +15,14 @@ import 'package:one_key/widgets/v_empty_view.dart'; |
|
14
|
import 'package:path_provider/path_provider.dart';
|
15
|
import 'package:path_provider/path_provider.dart';
|
|
15
|
import 'package:permission_handler/permission_handler.dart';
|
16
|
import 'package:permission_handler/permission_handler.dart';
|
|
16
|
|
17
|
|
|
|
|
18
|
+import '../../../../net/dio_util.dart';
|
|
17
|
import '../../../../utils/dialog_util.dart';
|
19
|
import '../../../../utils/dialog_util.dart';
|
|
18
|
import '../../../../utils/screen_util.dart';
|
20
|
import '../../../../utils/screen_util.dart';
|
|
19
|
import '../../../../utils/utils.dart';
|
21
|
import '../../../../utils/utils.dart';
|
|
20
|
import '../../../../widgets/h_empty_view.dart';
|
22
|
import '../../../../widgets/h_empty_view.dart';
|
|
21
|
import 'package:flutter_downloader/flutter_downloader.dart';
|
23
|
import 'package:flutter_downloader/flutter_downloader.dart';
|
|
22
|
import 'package:android_path_provider/android_path_provider.dart';
|
24
|
import 'package:android_path_provider/android_path_provider.dart';
|
|
|
|
25
|
+import 'package:open_file/open_file.dart';
|
|
23
|
|
26
|
|
|
24
|
/**
|
27
|
/**
|
|
25
|
* 导出预订数据
|
28
|
* 导出预订数据
|
|
@@ -51,14 +54,130 @@ class _ExportBookDataPageState extends State<ExportBookDataPage> { |
|
@@ -51,14 +54,130 @@ class _ExportBookDataPageState extends State<ExportBookDataPage> { |
|
51
|
void initState() {
|
54
|
void initState() {
|
|
52
|
super.initState();
|
55
|
super.initState();
|
|
53
|
|
56
|
|
|
54
|
- _bindBackgroundIsolate();
|
57
|
+ // IsolateNameServer.registerPortWithName(
|
|
|
|
58
|
+ // _port.sendPort, 'downloader_send_port');
|
|
|
|
59
|
+ // _port.listen((dynamic data) {
|
|
|
|
60
|
+ // taskId = data[0];
|
|
|
|
61
|
+ // status = DownloadTaskStatus(data[1]);
|
|
|
|
62
|
+ // progress = data[2];
|
|
|
|
63
|
+ // setState(() {});
|
|
|
|
64
|
+ // if (status == DownloadTaskStatus.undefined) {
|
|
|
|
65
|
+ // // _requestDownload(task);
|
|
|
|
66
|
+ // } else if (status == DownloadTaskStatus.running) {
|
|
|
|
67
|
+ // // _pauseDownload(task);
|
|
|
|
68
|
+ // // setState(() {});
|
|
|
|
69
|
+ // } else if (status == DownloadTaskStatus.paused) {
|
|
|
|
70
|
+ // // _resumeDownload(task);
|
|
|
|
71
|
+ // // setState(() {});
|
|
|
|
72
|
+ // } else if (status == DownloadTaskStatus.complete ||
|
|
|
|
73
|
+ // status == DownloadTaskStatus.canceled) {
|
|
|
|
74
|
+ // // _delete(task);
|
|
55
|
|
75
|
|
|
56
|
- FlutterDownloader.registerCallback(downloadCallback, step: 1);
|
76
|
+ // // 显示是否打开的对话框
|
|
|
|
77
|
+
|
|
|
|
78
|
+ // DialogUtil.cupertinoAlertDialog(context,
|
|
|
|
79
|
+ // title: '提示',
|
|
|
|
80
|
+ // content: '文件下载完成,是否打开?',
|
|
|
|
81
|
+ // lTitle: '取消',
|
|
|
|
82
|
+ // rTitle: '打开', lCallback: () {
|
|
|
|
83
|
+ // Navigator.pop(context);
|
|
|
|
84
|
+ // }, rCallback: () async {
|
|
|
|
85
|
+ // // Navigator.pop(context);
|
|
|
|
86
|
+
|
|
|
|
87
|
+ // print(_localPath);
|
|
|
|
88
|
+
|
|
|
|
89
|
+ // final tasks = await FlutterDownloader.loadTasks();
|
|
|
|
90
|
+ // String str = '';
|
|
|
|
91
|
+ // tasks.forEach((element) {
|
|
|
|
92
|
+ // str = element.savedDir + '/' + element.filename;
|
|
|
|
93
|
+ // });
|
|
|
|
94
|
+ // print(str);
|
|
|
|
95
|
+
|
|
|
|
96
|
+ // if (str != '') {
|
|
|
|
97
|
+ // OpenFile.open(str);
|
|
|
|
98
|
+ // _delete();
|
|
|
|
99
|
+ // }
|
|
|
|
100
|
+ // });
|
|
|
|
101
|
+ // // showDialog(
|
|
|
|
102
|
+ // // // 设置点击 dialog 外部不取消 dialog,默认能够取消
|
|
|
|
103
|
+ // // barrierDismissible: false,
|
|
|
|
104
|
+ // // context: context,
|
|
|
|
105
|
+ // // builder: (context) => AlertDialog(
|
|
|
|
106
|
+ // // title: Text('提示'),
|
|
|
|
107
|
+ // // // 标题文字样式
|
|
|
|
108
|
+ // // content: Text('文件下载完成,是否打开?'),
|
|
|
|
109
|
+ // // // 内容文字样式
|
|
|
|
110
|
+ // // backgroundColor: MyColours.color_ffffff,
|
|
|
|
111
|
+ // // elevation: 8.0,
|
|
|
|
112
|
+ // // // 投影的阴影高度
|
|
|
|
113
|
+ // // semanticLabel: 'Label',
|
|
|
|
114
|
+ // // // 这个用于无障碍下弹出 dialog 的提示
|
|
|
|
115
|
+ // // shape: Border.all(),
|
|
|
|
116
|
+ // // // dialog 的操作按钮,actions 的个数尽量控制不要过多,否则会溢出 `Overflow`
|
|
|
|
117
|
+ // // actions: <Widget>[
|
|
|
|
118
|
+ // // // 点击取消按钮
|
|
|
|
119
|
+ // // InkWell(
|
|
|
|
120
|
+ // // onTap: () => Navigator.pop(context), child: Text('取消')),
|
|
|
|
121
|
+ // // // 点击打开按钮
|
|
|
|
122
|
+ // // InkWell(
|
|
|
|
123
|
+ // // onTap: () async {
|
|
|
|
124
|
+ // // Navigator.pop(context);
|
|
|
|
125
|
+
|
|
|
|
126
|
+ // // print(_localPath);
|
|
|
|
127
|
+
|
|
|
|
128
|
+ // // final tasks = await FlutterDownloader.loadTasks();
|
|
|
|
129
|
+ // // String str = '';
|
|
|
|
130
|
+ // // tasks.forEach((element) {
|
|
|
|
131
|
+ // // str = element.savedDir + '/' + element.filename;
|
|
|
|
132
|
+ // // });
|
|
|
|
133
|
+ // // print(str);
|
|
|
|
134
|
+ // // if (str != '') {
|
|
|
|
135
|
+ // // OpenFile.open(str);
|
|
|
|
136
|
+ // // }
|
|
|
|
137
|
+
|
|
|
|
138
|
+ // // // 打开文件
|
|
|
|
139
|
+ // // // _openDownloadedFile(taskId).then((success) {
|
|
|
|
140
|
+ // // // if (!success) {
|
|
|
|
141
|
+ // // // Utils.showToast('Cannot open this file');
|
|
|
|
142
|
+ // // // // Scaffold.of(context).showSnackBar(SnackBar(
|
|
|
|
143
|
+ // // // // content: Text('Cannot open this file')));
|
|
|
|
144
|
+ // // // }
|
|
|
|
145
|
+ // // // });
|
|
|
|
146
|
+ // // },
|
|
|
|
147
|
+ // // child: Text('打开')),
|
|
|
|
148
|
+ // // ],
|
|
|
|
149
|
+ // // ));
|
|
|
|
150
|
+ // } else if (status == DownloadTaskStatus.failed) {
|
|
|
|
151
|
+ // // _retryDownload(task);
|
|
|
|
152
|
+ // Utils.showToast('下载异常,请稍后重试');
|
|
|
|
153
|
+ // }
|
|
|
|
154
|
+ // });
|
|
|
|
155
|
+
|
|
|
|
156
|
+ // FlutterDownloader.registerCallback(downloadCallback);
|
|
|
|
157
|
+
|
|
|
|
158
|
+ // // _bindBackgroundIsolate();
|
|
|
|
159
|
+
|
|
|
|
160
|
+ // // FlutterDownloader.registerCallback(downloadCallback, step: 1);
|
|
|
|
161
|
+ // _delete();
|
|
57
|
}
|
162
|
}
|
|
58
|
|
163
|
|
|
|
|
164
|
+ // _preae() async {
|
|
|
|
165
|
+ // final tasks = await FlutterDownloader.loadTasks();
|
|
|
|
166
|
+
|
|
|
|
167
|
+ // if (tasks == null) {
|
|
|
|
168
|
+ // print('No tasks were retrieved from the database.');
|
|
|
|
169
|
+ // return;
|
|
|
|
170
|
+ // } else {
|
|
|
|
171
|
+ // tasks.forEach((element) {
|
|
|
|
172
|
+ // FlutterDownloader.remove(
|
|
|
|
173
|
+ // taskId: element.taskId, shouldDeleteContent: false);
|
|
|
|
174
|
+ // });
|
|
|
|
175
|
+ // }
|
|
|
|
176
|
+ // }
|
|
|
|
177
|
+
|
|
59
|
@override
|
178
|
@override
|
|
60
|
void dispose() {
|
179
|
void dispose() {
|
|
61
|
- _unbindBackgroundIsolate();
|
180
|
+ // _unbindBackgroundIsolate();
|
|
62
|
super.dispose();
|
181
|
super.dispose();
|
|
63
|
}
|
182
|
}
|
|
64
|
|
183
|
|
|
@@ -68,13 +187,9 @@ class _ExportBookDataPageState extends State<ExportBookDataPage> { |
|
@@ -68,13 +187,9 @@ class _ExportBookDataPageState extends State<ExportBookDataPage> { |
|
68
|
int status,
|
187
|
int status,
|
|
69
|
int progress,
|
188
|
int progress,
|
|
70
|
) {
|
189
|
) {
|
|
71
|
- print(
|
|
|
|
72
|
- 'Callback on background isolate: '
|
|
|
|
73
|
- 'task ($id) is in status ($status) and process ($progress)',
|
|
|
|
74
|
- );
|
|
|
|
75
|
-
|
|
|
|
76
|
- IsolateNameServer.lookupPortByName('downloader_send_port')
|
|
|
|
77
|
- ?.send([id, status, progress]);
|
190
|
+ final SendPort send =
|
|
|
|
191
|
+ IsolateNameServer.lookupPortByName('downloader_send_port');
|
|
|
|
192
|
+ send.send([id, status, progress]);
|
|
78
|
}
|
193
|
}
|
|
79
|
|
194
|
|
|
80
|
// 根据taskId打开下载文件
|
195
|
// 根据taskId打开下载文件
|
|
@@ -82,75 +197,89 @@ class _ExportBookDataPageState extends State<ExportBookDataPage> { |
|
@@ -82,75 +197,89 @@ class _ExportBookDataPageState extends State<ExportBookDataPage> { |
|
82
|
return FlutterDownloader.open(taskId: taskId);
|
197
|
return FlutterDownloader.open(taskId: taskId);
|
|
83
|
}
|
198
|
}
|
|
84
|
|
199
|
|
|
85
|
- void _bindBackgroundIsolate() {
|
|
|
|
86
|
- final isSuccess = IsolateNameServer.registerPortWithName(
|
|
|
|
87
|
- _port.sendPort,
|
|
|
|
88
|
- 'downloader_send_port',
|
|
|
|
89
|
- );
|
|
|
|
90
|
- if (!isSuccess) {
|
|
|
|
91
|
- _unbindBackgroundIsolate();
|
|
|
|
92
|
- _bindBackgroundIsolate();
|
|
|
|
93
|
- return;
|
200
|
+ // void _bindBackgroundIsolate() {
|
|
|
|
201
|
+ // final isSuccess = IsolateNameServer.registerPortWithName(
|
|
|
|
202
|
+ // _port.sendPort,
|
|
|
|
203
|
+ // 'downloader_send_port',
|
|
|
|
204
|
+ // );
|
|
|
|
205
|
+ // if (!isSuccess) {
|
|
|
|
206
|
+ // _unbindBackgroundIsolate();
|
|
|
|
207
|
+ // _bindBackgroundIsolate();
|
|
|
|
208
|
+ // return;
|
|
|
|
209
|
+ // }
|
|
|
|
210
|
+ // _port.listen((dynamic data) {
|
|
|
|
211
|
+ // taskId = (data as List<dynamic>)[0] as String;
|
|
|
|
212
|
+ // status = DownloadTaskStatus(data[1] as int);
|
|
|
|
213
|
+ // progressT = data[2] as int;
|
|
|
|
214
|
+
|
|
|
|
215
|
+ // print(
|
|
|
|
216
|
+ // 'Callback on UI isolate: '
|
|
|
|
217
|
+ // 'task ($taskId) is in status ($status) and process ($progressT)',
|
|
|
|
218
|
+ // );
|
|
|
|
219
|
+ // if (status == DownloadTaskStatus.undefined) {
|
|
|
|
220
|
+ // // _requestDownload(task);
|
|
|
|
221
|
+ // } else if (status == DownloadTaskStatus.running) {
|
|
|
|
222
|
+ // // _pauseDownload(task);
|
|
|
|
223
|
+ // setState(() {});
|
|
|
|
224
|
+ // } else if (status == DownloadTaskStatus.paused) {
|
|
|
|
225
|
+ // // _resumeDownload(task);
|
|
|
|
226
|
+ // setState(() {});
|
|
|
|
227
|
+ // } else if (status == DownloadTaskStatus.complete ||
|
|
|
|
228
|
+ // status == DownloadTaskStatus.canceled) {
|
|
|
|
229
|
+ // // _delete(task);
|
|
|
|
230
|
+ // // 显示是否打开的对话框
|
|
|
|
231
|
+ // showDialog(
|
|
|
|
232
|
+ // // 设置点击 dialog 外部不取消 dialog,默认能够取消
|
|
|
|
233
|
+ // barrierDismissible: false,
|
|
|
|
234
|
+ // context: context,
|
|
|
|
235
|
+ // builder: (context) => AlertDialog(
|
|
|
|
236
|
+ // title: Text('提示'),
|
|
|
|
237
|
+ // // 标题文字样式
|
|
|
|
238
|
+ // content: Text('文件下载完成,是否打开?'),
|
|
|
|
239
|
+ // // 内容文字样式
|
|
|
|
240
|
+ // backgroundColor: MyColours.color_ffffff,
|
|
|
|
241
|
+ // elevation: 8.0,
|
|
|
|
242
|
+ // // 投影的阴影高度
|
|
|
|
243
|
+ // semanticLabel: 'Label',
|
|
|
|
244
|
+ // // 这个用于无障碍下弹出 dialog 的提示
|
|
|
|
245
|
+ // shape: Border.all(),
|
|
|
|
246
|
+ // // dialog 的操作按钮,actions 的个数尽量控制不要过多,否则会溢出 `Overflow`
|
|
|
|
247
|
+ // actions: <Widget>[
|
|
|
|
248
|
+ // // 点击取消按钮
|
|
|
|
249
|
+ // InkWell(
|
|
|
|
250
|
+ // onTap: () => Navigator.pop(context), child: Text('取消')),
|
|
|
|
251
|
+ // // 点击打开按钮
|
|
|
|
252
|
+ // InkWell(
|
|
|
|
253
|
+ // onTap: () {
|
|
|
|
254
|
+ // Navigator.pop(context);
|
|
|
|
255
|
+ // // 打开文件
|
|
|
|
256
|
+ // _openDownloadedFile(taskId).then((success) {
|
|
|
|
257
|
+ // if (!success) {
|
|
|
|
258
|
+ // Utils.showToast('Cannot open this file');
|
|
|
|
259
|
+ // // Scaffold.of(context).showSnackBar(SnackBar(
|
|
|
|
260
|
+ // // content: Text('Cannot open this file')));
|
|
|
|
261
|
+ // }
|
|
|
|
262
|
+ // });
|
|
|
|
263
|
+ // },
|
|
|
|
264
|
+ // child: Text('打开')),
|
|
|
|
265
|
+ // ],
|
|
|
|
266
|
+ // ));
|
|
|
|
267
|
+ // } else if (status == DownloadTaskStatus.failed) {
|
|
|
|
268
|
+ // // _retryDownload(task);
|
|
|
|
269
|
+ // Utils.showToast('下载异常,请稍后重试');
|
|
|
|
270
|
+ // }
|
|
|
|
271
|
+ // });
|
|
|
|
272
|
+ // }
|
|
|
|
273
|
+ Future<void> _delete() async {
|
|
|
|
274
|
+ final task = await FlutterDownloader.loadTasks();
|
|
|
|
275
|
+ if (task != null) {
|
|
|
|
276
|
+ task.forEach((element) {
|
|
|
|
277
|
+ FlutterDownloader.remove(
|
|
|
|
278
|
+ taskId: element.taskId,
|
|
|
|
279
|
+ shouldDeleteContent: true,
|
|
|
|
280
|
+ );
|
|
|
|
281
|
+ });
|
|
94
|
}
|
282
|
}
|
|
95
|
- _port.listen((dynamic data) {
|
|
|
|
96
|
- taskId = (data as List<dynamic>)[0] as String;
|
|
|
|
97
|
- status = DownloadTaskStatus(data[1] as int);
|
|
|
|
98
|
- progress = data[2] as int;
|
|
|
|
99
|
-
|
|
|
|
100
|
- print(
|
|
|
|
101
|
- 'Callback on UI isolate: '
|
|
|
|
102
|
- 'task ($taskId) is in status ($status) and process ($progress)',
|
|
|
|
103
|
- );
|
|
|
|
104
|
- if (status == DownloadTaskStatus.undefined) {
|
|
|
|
105
|
- // _requestDownload(task);
|
|
|
|
106
|
- } else if (status == DownloadTaskStatus.running) {
|
|
|
|
107
|
- // _pauseDownload(task);
|
|
|
|
108
|
- } else if (status == DownloadTaskStatus.paused) {
|
|
|
|
109
|
- // _resumeDownload(task);
|
|
|
|
110
|
- } else if (status == DownloadTaskStatus.complete ||
|
|
|
|
111
|
- status == DownloadTaskStatus.canceled) {
|
|
|
|
112
|
- // _delete(task);
|
|
|
|
113
|
- // 显示是否打开的对话框
|
|
|
|
114
|
- showDialog(
|
|
|
|
115
|
- // 设置点击 dialog 外部不取消 dialog,默认能够取消
|
|
|
|
116
|
- barrierDismissible: false,
|
|
|
|
117
|
- context: context,
|
|
|
|
118
|
- builder: (context) => AlertDialog(
|
|
|
|
119
|
- title: Text('提示'),
|
|
|
|
120
|
- // 标题文字样式
|
|
|
|
121
|
- content: Text('文件下载完成,是否打开?'),
|
|
|
|
122
|
- // 内容文字样式
|
|
|
|
123
|
- backgroundColor: MyColours.color_ffffff,
|
|
|
|
124
|
- elevation: 8.0,
|
|
|
|
125
|
- // 投影的阴影高度
|
|
|
|
126
|
- semanticLabel: 'Label',
|
|
|
|
127
|
- // 这个用于无障碍下弹出 dialog 的提示
|
|
|
|
128
|
- shape: Border.all(),
|
|
|
|
129
|
- // dialog 的操作按钮,actions 的个数尽量控制不要过多,否则会溢出 `Overflow`
|
|
|
|
130
|
- actions: <Widget>[
|
|
|
|
131
|
- // 点击取消按钮
|
|
|
|
132
|
- InkWell(
|
|
|
|
133
|
- onTap: () => Navigator.pop(context), child: Text('取消')),
|
|
|
|
134
|
- // 点击打开按钮
|
|
|
|
135
|
- InkWell(
|
|
|
|
136
|
- onTap: () {
|
|
|
|
137
|
- Navigator.pop(context);
|
|
|
|
138
|
- // 打开文件
|
|
|
|
139
|
- _openDownloadedFile(taskId).then((success) {
|
|
|
|
140
|
- if (!success) {
|
|
|
|
141
|
- Utils.showToast('Cannot open this file');
|
|
|
|
142
|
- // Scaffold.of(context).showSnackBar(SnackBar(
|
|
|
|
143
|
- // content: Text('Cannot open this file')));
|
|
|
|
144
|
- }
|
|
|
|
145
|
- });
|
|
|
|
146
|
- },
|
|
|
|
147
|
- child: Text('打开')),
|
|
|
|
148
|
- ],
|
|
|
|
149
|
- ));
|
|
|
|
150
|
- } else if (status == DownloadTaskStatus.failed) {
|
|
|
|
151
|
- // _retryDownload(task);
|
|
|
|
152
|
- }
|
|
|
|
153
|
- });
|
|
|
|
154
|
}
|
283
|
}
|
|
155
|
|
284
|
|
|
156
|
Future<void> _prepareSaveDir() async {
|
285
|
Future<void> _prepareSaveDir() async {
|
|
@@ -165,14 +294,14 @@ class _ExportBookDataPageState extends State<ExportBookDataPage> { |
|
@@ -165,14 +294,14 @@ class _ExportBookDataPageState extends State<ExportBookDataPage> { |
|
165
|
String externalStorageDirPath;
|
294
|
String externalStorageDirPath;
|
|
166
|
|
295
|
|
|
167
|
if (Platform.isAndroid) {
|
296
|
if (Platform.isAndroid) {
|
|
168
|
- try {
|
|
|
|
169
|
- externalStorageDirPath = await AndroidPathProvider.downloadsPath;
|
|
|
|
170
|
- } catch (err, st) {
|
|
|
|
171
|
- print('failed to get downloads path: $err, $st');
|
297
|
+ // try {
|
|
|
|
298
|
+ // externalStorageDirPath = await AndroidPathProvider.downloadsPath;
|
|
|
|
299
|
+ // } catch (err, st) {
|
|
|
|
300
|
+ // print('failed to get downloads path: $err, $st');
|
|
172
|
|
301
|
|
|
173
|
- final directory = await getExternalStorageDirectory();
|
|
|
|
174
|
- externalStorageDirPath = directory?.path;
|
|
|
|
175
|
- }
|
302
|
+ final directory = await getExternalStorageDirectory();
|
|
|
|
303
|
+ externalStorageDirPath = directory?.path;
|
|
|
|
304
|
+ // }
|
|
176
|
} else if (Platform.isIOS) {
|
305
|
} else if (Platform.isIOS) {
|
|
177
|
externalStorageDirPath =
|
306
|
externalStorageDirPath =
|
|
178
|
(await getApplicationDocumentsDirectory()).absolute.path;
|
307
|
(await getApplicationDocumentsDirectory()).absolute.path;
|
|
@@ -186,10 +315,10 @@ class _ExportBookDataPageState extends State<ExportBookDataPage> { |
|
@@ -186,10 +315,10 @@ class _ExportBookDataPageState extends State<ExportBookDataPage> { |
|
186
|
}
|
315
|
}
|
|
187
|
|
316
|
|
|
188
|
if (Platform.isAndroid) {
|
317
|
if (Platform.isAndroid) {
|
|
189
|
- final info = await DeviceInfoPlugin().androidInfo;
|
|
|
|
190
|
- if (info.version.sdkInt > 28) {
|
|
|
|
191
|
- return true;
|
|
|
|
192
|
- }
|
318
|
+ // final info = await DeviceInfoPlugin().androidInfo;
|
|
|
|
319
|
+ // if (info.version.sdkInt > 28) {
|
|
|
|
320
|
+ // return true;
|
|
|
|
321
|
+ // }
|
|
193
|
|
322
|
|
|
194
|
final status = await Permission.storage.status;
|
323
|
final status = await Permission.storage.status;
|
|
195
|
if (status == PermissionStatus.granted) {
|
324
|
if (status == PermissionStatus.granted) {
|
|
@@ -299,8 +428,14 @@ class _ExportBookDataPageState extends State<ExportBookDataPage> { |
|
@@ -299,8 +428,14 @@ class _ExportBookDataPageState extends State<ExportBookDataPage> { |
|
299
|
// controller: controller,
|
428
|
// controller: controller,
|
|
300
|
child: Column(
|
429
|
child: Column(
|
|
301
|
children: [
|
430
|
children: [
|
|
302
|
- (status == DownloadTaskStatus.running ||
|
|
|
|
303
|
- status == DownloadTaskStatus.paused)
|
431
|
+ // (status == DownloadTaskStatus.running ||
|
|
|
|
432
|
+ // status == DownloadTaskStatus.paused)
|
|
|
|
433
|
+ // ? LinearProgressIndicator(
|
|
|
|
434
|
+ // value: progress / 100,
|
|
|
|
435
|
+ // )
|
|
|
|
436
|
+ // : VEmptyView(10),
|
|
|
|
437
|
+
|
|
|
|
438
|
+ progress != null && progress != 100
|
|
304
|
? LinearProgressIndicator(
|
439
|
? LinearProgressIndicator(
|
|
305
|
value: progress / 100,
|
440
|
value: progress / 100,
|
|
306
|
)
|
441
|
)
|
|
@@ -404,7 +539,9 @@ class _ExportBookDataPageState extends State<ExportBookDataPage> { |
|
@@ -404,7 +539,9 @@ class _ExportBookDataPageState extends State<ExportBookDataPage> { |
|
404
|
),
|
539
|
),
|
|
405
|
VEmptyView(26),
|
540
|
VEmptyView(26),
|
|
406
|
RoundButton(
|
541
|
RoundButton(
|
|
407
|
- text: '导出数据',
|
542
|
+ text: (progress != null && progress != 100)
|
|
|
|
543
|
+ ? '${progress}%'
|
|
|
|
544
|
+ : '导出数据',
|
|
408
|
width: w(218),
|
545
|
width: w(218),
|
|
409
|
height: w(43),
|
546
|
height: w(43),
|
|
410
|
gradientStart: MyColours.color_f3f3f3,
|
547
|
gradientStart: MyColours.color_f3f3f3,
|
|
@@ -415,22 +552,86 @@ class _ExportBookDataPageState extends State<ExportBookDataPage> { |
|
@@ -415,22 +552,86 @@ class _ExportBookDataPageState extends State<ExportBookDataPage> { |
|
415
|
fontSize: 32,
|
552
|
fontSize: 32,
|
|
416
|
isBold: true,
|
553
|
isBold: true,
|
|
417
|
onPressed: () async {
|
554
|
onPressed: () async {
|
|
|
|
555
|
+ if (progress != null) {
|
|
|
|
556
|
+ return;
|
|
|
|
557
|
+ }
|
|
|
|
558
|
+
|
|
418
|
bool _permissionReady = await _checkPermission();
|
559
|
bool _permissionReady = await _checkPermission();
|
|
419
|
if (_permissionReady) {
|
560
|
if (_permissionReady) {
|
|
420
|
await _prepareSaveDir();
|
561
|
await _prepareSaveDir();
|
|
421
|
}
|
562
|
}
|
|
422
|
- taskId = await FlutterDownloader.enqueue(
|
|
|
|
423
|
- url:
|
563
|
+ // _delete();
|
|
|
|
564
|
+ String savePath = _localPath + "/fff.pdf";
|
|
|
|
565
|
+ Directory directory = new Directory(savePath);
|
|
|
|
566
|
+ if (directory.existsSync()) {
|
|
|
|
567
|
+ //删除历史
|
|
|
|
568
|
+ final List<FileSystemEntity> files = directory.listSync();
|
|
|
|
569
|
+ for (FileSystemEntity file in files) {
|
|
|
|
570
|
+ file.deleteSync();
|
|
|
|
571
|
+ }
|
|
|
|
572
|
+ }
|
|
|
|
573
|
+
|
|
|
|
574
|
+ try {
|
|
|
|
575
|
+ Response response = await DioUtil().download(
|
|
424
|
'http://englishonlineclub.com/pdf/iOS%20Programming%20-%20The%20Big%20Nerd%20Ranch%20Guide%20(6th%20Edition)%20[EnglishOnlineClub.com].pdf',
|
576
|
'http://englishonlineclub.com/pdf/iOS%20Programming%20-%20The%20Big%20Nerd%20Ranch%20Guide%20(6th%20Edition)%20[EnglishOnlineClub.com].pdf',
|
|
425
|
- headers: {
|
|
|
|
426
|
- 'auth': 'test_for_sql_encoding'
|
|
|
|
427
|
- }, // optional: header send with url (auth token etc)
|
|
|
|
428
|
- savedDir: _localPath,
|
|
|
|
429
|
- showNotification:
|
|
|
|
430
|
- true, // show download progress in status bar (for Android)
|
|
|
|
431
|
- openFileFromNotification:
|
|
|
|
432
|
- true, // click on notification to open downloaded file (for Android)
|
|
|
|
433
|
- );
|
577
|
+ savePath, onProgress: (received, total) {
|
|
|
|
578
|
+ if (progress != 100) {
|
|
|
|
579
|
+ progress = ((received / total) * 100).round();
|
|
|
|
580
|
+
|
|
|
|
581
|
+ setState(() {});
|
|
|
|
582
|
+ }
|
|
|
|
583
|
+ if (received == total) {
|
|
|
|
584
|
+ //下载完成
|
|
|
|
585
|
+ print('xaizaiwancheng');
|
|
|
|
586
|
+
|
|
|
|
587
|
+ DialogUtil.cupertinoAlertDialog(context,
|
|
|
|
588
|
+ title: '提示',
|
|
|
|
589
|
+ content: '文件下载完成,是否打开?',
|
|
|
|
590
|
+ lTitle: '取消',
|
|
|
|
591
|
+ rTitle: '打开', lCallback: () {
|
|
|
|
592
|
+ progress = null;
|
|
|
|
593
|
+ setState(() {});
|
|
|
|
594
|
+ }, rCallback: () async {
|
|
|
|
595
|
+ // Navigator.pop(context);
|
|
|
|
596
|
+
|
|
|
|
597
|
+ // print(_localPath);
|
|
|
|
598
|
+
|
|
|
|
599
|
+ // final tasks = await FlutterDownloader.loadTasks();
|
|
|
|
600
|
+ // String str = '';
|
|
|
|
601
|
+ // tasks.forEach((element) {
|
|
|
|
602
|
+ // str = element.savedDir + '/' + element.filename;
|
|
|
|
603
|
+ // });
|
|
|
|
604
|
+ // print(str);
|
|
|
|
605
|
+
|
|
|
|
606
|
+ // if (str != '') {
|
|
|
|
607
|
+ print(savePath);
|
|
|
|
608
|
+ progress = null;
|
|
|
|
609
|
+ setState(() {});
|
|
|
|
610
|
+ OpenFile.open(savePath);
|
|
|
|
611
|
+ // _delete();
|
|
|
|
612
|
+ // }
|
|
|
|
613
|
+ });
|
|
|
|
614
|
+ }
|
|
|
|
615
|
+ });
|
|
|
|
616
|
+ print(response);
|
|
|
|
617
|
+ } catch (e) {
|
|
|
|
618
|
+ print(e);
|
|
|
|
619
|
+ }
|
|
|
|
620
|
+
|
|
|
|
621
|
+ // taskId = await FlutterDownloader.enqueue(
|
|
|
|
622
|
+ // url:
|
|
|
|
623
|
+ // 'http://englishonlineclub.com/pdf/iOS%20Programming%20-%20The%20Big%20Nerd%20Ranch%20Guide%20(6th%20Edition)%20[EnglishOnlineClub.com].pdf',
|
|
|
|
624
|
+ // headers: {
|
|
|
|
625
|
+ // // 'auth': 'test_for_sql_encoding'
|
|
|
|
626
|
+ // }, // optional: header send with url (auth token etc)
|
|
|
|
627
|
+ // savedDir: _localPath,
|
|
|
|
628
|
+ // saveInPublicStorage: true,
|
|
|
|
629
|
+ // // fileName:
|
|
|
|
630
|
+ // // // showNotification:
|
|
|
|
631
|
+ // // // true, // show download progress in status bar (for Android)
|
|
|
|
632
|
+ // // openFileFromNotification:
|
|
|
|
633
|
+ // // true, // click on notification to open downloaded file (for Android)
|
|
|
|
634
|
+ // );
|
|
434
|
},
|
635
|
},
|
|
435
|
)
|
636
|
)
|
|
436
|
],
|
637
|
],
|