|
...
|
...
|
@@ -6,6 +6,7 @@ import 'package:common_utils/common_utils.dart'; |
|
|
|
import 'package:device_info/device_info.dart';
|
|
|
|
import 'package:dio/dio.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter/services.dart';
|
|
|
|
import 'package:flutter_picker/Picker.dart';
|
|
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
|
|
import 'package:one_key/models/get_export_info_model.dart';
|
|
...
|
...
|
@@ -28,11 +29,16 @@ import '../../../../utils/utils.dart'; |
|
|
|
import '../../../../widgets/h_empty_view.dart';
|
|
|
|
// import 'package:flutter_downloader/flutter_downloader.dart';
|
|
|
|
// import 'package:android_path_provider/android_path_provider.dart';
|
|
|
|
import 'package:open_file/open_file.dart';
|
|
|
|
// import 'package:open_file/open_file.dart';
|
|
|
|
import 'package:open_filex/open_filex.dart';
|
|
|
|
import 'package:excel/excel.dart' as excelUtil;
|
|
|
|
|
|
|
|
import '../../../../widgets/loading.dart';
|
|
|
|
|
|
|
|
import 'package:external_path/external_path.dart';
|
|
|
|
// import 'package:open_file_plus/open_file_plus.dart';
|
|
|
|
// import 'package:flutter_filereader/flutter_filereader.dart';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 导出预订数据
|
|
|
|
*/
|
|
...
|
...
|
@@ -52,17 +58,14 @@ class _ExportBookDataPageState extends State<ExportBookDataPage> { |
|
|
|
|
|
|
|
List<String> data = ['到店时间', '下单时间'];
|
|
|
|
int timeIndex;
|
|
|
|
// ReceivePort _port = ReceivePort();
|
|
|
|
|
|
|
|
String _localPath;
|
|
|
|
|
|
|
|
String taskId;
|
|
|
|
// DownloadTaskStatus status;
|
|
|
|
int progress;
|
|
|
|
|
|
|
|
CustomerProvider customerProvider;
|
|
|
|
|
|
|
|
// List<Map<String, String>> fieldData = {};
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
|
...
|
...
|
@@ -73,12 +76,9 @@ class _ExportBookDataPageState extends State<ExportBookDataPage> { |
|
|
|
}
|
|
|
|
|
|
|
|
_getReportField() async {
|
|
|
|
bool success = await customerProvider.getReportField(context);
|
|
|
|
// if (success) {
|
|
|
|
// customerProvider.reportFieldModelData.forEach((element) {
|
|
|
|
// fieldData[element.code] = element.name;
|
|
|
|
// });
|
|
|
|
// }
|
|
|
|
await customerProvider.getReportField(context);
|
|
|
|
|
|
|
|
await _checkPermission();
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> _prepareSaveDir() async {
|
|
...
|
...
|
@@ -93,23 +93,9 @@ class _ExportBookDataPageState extends State<ExportBookDataPage> { |
|
|
|
String externalStorageDirPath;
|
|
|
|
|
|
|
|
if (Platform.isAndroid) {
|
|
|
|
// try {
|
|
|
|
// externalStorageDirPath = await AndroidPathProvider.downloadsPath;
|
|
|
|
// } catch (err, st) {
|
|
|
|
// print('failed to get downloads path: $err, $st');
|
|
|
|
|
|
|
|
// if()/
|
|
|
|
|
|
|
|
// final directory = await getExternalStorageDirectory();
|
|
|
|
// externalStorageDirPath = directory?.path;
|
|
|
|
|
|
|
|
externalStorageDirPath = '/storage/emulated/0/Download';
|
|
|
|
final directory = await getExternalStorageDirectory();
|
|
|
|
externalStorageDirPath = directory?.path;
|
|
|
|
} else if (Platform.isIOS) {
|
|
|
|
// externalStorageDirPath =
|
|
|
|
// (await getApplicationDocumentsDirectory()).absolute.path;
|
|
|
|
|
|
|
|
// externalStorageDirPath = (await getTemporaryDirectory()).path;
|
|
|
|
|
|
|
|
externalStorageDirPath = (await getApplicationSupportDirectory()).path;
|
|
|
|
|
|
|
|
externalStorageDirPath =
|
|
...
|
...
|
@@ -124,38 +110,42 @@ class _ExportBookDataPageState extends State<ExportBookDataPage> { |
|
|
|
}
|
|
|
|
|
|
|
|
if (Platform.isAndroid) {
|
|
|
|
// final info = await DeviceInfoPlugin().androidInfo;
|
|
|
|
// if (info.version.sdkInt > 28) {
|
|
|
|
// return true;
|
|
|
|
// }
|
|
|
|
|
|
|
|
final status = await Permission.manageExternalStorage.status;
|
|
|
|
if (status == PermissionStatus.granted) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
final info = await DeviceInfoPlugin().androidInfo;
|
|
|
|
|
|
|
|
if (Platform.isAndroid) {
|
|
|
|
// try {
|
|
|
|
// externalStorageDirPath = await AndroidPathProvider.downloadsPath;
|
|
|
|
// } catch (err, st) {
|
|
|
|
// print('failed to get downloads path: $err, $st');
|
|
|
|
if (info.version.sdkInt >= 33) {
|
|
|
|
final status = await Permission.photos.status;
|
|
|
|
if (status == PermissionStatus.granted) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (status != PermissionStatus.permanentlyDenied) {
|
|
|
|
//全局提示权限使用目的
|
|
|
|
BuildContext context = App.navigatorKey.currentState.overlay.context;
|
|
|
|
dynamic object = DialogUtil.showAuthorityDestination(
|
|
|
|
context, 'h_storage', '访问照片和视频权限', '用于存储下载的预订表。');
|
|
|
|
print(object);
|
|
|
|
}
|
|
|
|
|
|
|
|
// if()/
|
|
|
|
PermissionStatus permissionStatus =
|
|
|
|
await Permission.manageExternalStorage.status;
|
|
|
|
final result = await Permission.photos.request();
|
|
|
|
return result == PermissionStatus.granted;
|
|
|
|
} else {
|
|
|
|
final status = await Permission.storage.status;
|
|
|
|
if (status == PermissionStatus.granted) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (permissionStatus != PermissionStatus.permanentlyDenied) {
|
|
|
|
if (status != PermissionStatus.permanentlyDenied) {
|
|
|
|
//全局提示权限使用目的
|
|
|
|
BuildContext context = App.navigatorKey.currentState.overlay.context;
|
|
|
|
DialogUtil.showAuthorityDestination(
|
|
|
|
context, 'h_storage', '访问所有文件权限', '用于存储下载的预订表。');
|
|
|
|
context, 'h_storage', '访问存储权限', '用于存储下载的预订表。');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
final result = await Permission.manageExternalStorage.request();
|
|
|
|
return result == PermissionStatus.granted;
|
|
|
|
final result = await Permission.storage.request();
|
|
|
|
return result == PermissionStatus.granted;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// manageExternalStorage
|
|
|
|
throw StateError('unknown platform');
|
|
|
|
}
|
|
|
|
|
|
...
|
...
|
@@ -338,25 +328,29 @@ class _ExportBookDataPageState extends State<ExportBookDataPage> { |
|
|
|
Provider.of<UserModel>(context, listen: false).user.sellername;
|
|
|
|
String starttime = fromDate.replaceAll('-', '');
|
|
|
|
String endtime = endDate.replaceAll('-', '');
|
|
|
|
String fileName = "/${sellername}${starttime}至${endtime}.xlsx";
|
|
|
|
String nameS = '/${sellername}${starttime}至${endtime}_';
|
|
|
|
String timetemp =
|
|
|
|
((DateTime.now().millisecondsSinceEpoch / 1000).floor()).toString();
|
|
|
|
String sunfix = '.xlsx';
|
|
|
|
|
|
|
|
// String sunfix = '.xls';
|
|
|
|
// String fileName = "/${sellername}${starttime}至${endtime}.xlsx";
|
|
|
|
String fileName = nameS + timetemp + sunfix;
|
|
|
|
if (Platform.isIOS) {
|
|
|
|
fileName = nameS + sunfix;
|
|
|
|
}
|
|
|
|
String filePath = _localPath + '${fileName}';
|
|
|
|
// Utils.showToast('文件已保存到${filePath}');
|
|
|
|
|
|
|
|
if (fileBytes != null) {
|
|
|
|
// File file =
|
|
|
|
File(filePath)
|
|
|
|
File file = File(filePath)
|
|
|
|
..createSync(recursive: true)
|
|
|
|
..writeAsBytesSync(fileBytes);
|
|
|
|
// try {
|
|
|
|
// // File file1 = File('/storage/emulated/0/Download${fileName}')
|
|
|
|
// // ..createSync(recursive: true)
|
|
|
|
// // ..writeAsBytesSync(fileBytes);
|
|
|
|
// // File file2 =
|
|
|
|
// // await file.copy('/storage/emulated/0/Documents${fileName}');
|
|
|
|
// File file1 = await file.copy('/storage/emulated/0/Download${fileName}');
|
|
|
|
// Utils.showToast('文件已保存到${file1.path}');
|
|
|
|
// } catch (e) {
|
|
|
|
// Utils.showToast('保存失败:${e}');
|
|
|
|
// }
|
|
|
|
try {
|
|
|
|
File file1 = await file.copy('/storage/emulated/0/Download${fileName}');
|
|
|
|
// Utils.showToast('文件已保存到${file1.path}');
|
|
|
|
} catch (e) {
|
|
|
|
// Utils.showToast('保存失败!');
|
|
|
|
}
|
|
|
|
|
|
|
|
Loading.hideLoading(context);
|
|
|
|
DialogUtil.cupertinoAlertDialog(context,
|
|
...
|
...
|
@@ -369,24 +363,21 @@ class _ExportBookDataPageState extends State<ExportBookDataPage> { |
|
|
|
progress = null;
|
|
|
|
setState(() {});
|
|
|
|
}, rCallback: () async {
|
|
|
|
// Navigator.pop(context);
|
|
|
|
|
|
|
|
// print(_localPath);
|
|
|
|
|
|
|
|
// final tasks = await FlutterDownloader.loadTasks();
|
|
|
|
// String str = '';
|
|
|
|
// tasks.forEach((element) {
|
|
|
|
// str = element.savedDir + '/' + element.filename;
|
|
|
|
// });
|
|
|
|
// print(str);
|
|
|
|
|
|
|
|
// if (str != '') {
|
|
|
|
// print(savePath);
|
|
|
|
// progress = null;
|
|
|
|
// setState(() {});
|
|
|
|
OpenFile.open(filePath);
|
|
|
|
// _delete();
|
|
|
|
// }
|
|
|
|
// final result =
|
|
|
|
// await OpenFilex.open(filePath, type: 'application/vnd.ms-excel');
|
|
|
|
final result = await OpenFilex.open(filePath,
|
|
|
|
type:
|
|
|
|
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
|
|
|
|
print(result.type);
|
|
|
|
if (result.type == ResultType.noAppToOpen) {
|
|
|
|
Utils.showToast('没有应用可以打开');
|
|
|
|
} else if (result.type == ResultType.fileNotFound) {
|
|
|
|
Utils.showToast('找不到文件');
|
|
|
|
} else if (result.type == ResultType.permissionDenied) {
|
|
|
|
Utils.showToast('没有相关权限');
|
|
|
|
} else if (result.type == ResultType.permissionDenied) {
|
|
|
|
Utils.showToast('发生未知错误');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
Loading.hideLoading(context);
|
|
...
|
...
|
@@ -412,13 +403,6 @@ class _ExportBookDataPageState extends State<ExportBookDataPage> { |
|
|
|
// controller: controller,
|
|
|
|
child: Column(
|
|
|
|
children: [
|
|
|
|
// (status == DownloadTaskStatus.running ||
|
|
|
|
// status == DownloadTaskStatus.paused)
|
|
|
|
// ? LinearProgressIndicator(
|
|
|
|
// value: progress / 100,
|
|
|
|
// )
|
|
|
|
// : VEmptyView(10),
|
|
|
|
|
|
|
|
progress != null && progress != 100
|
|
|
|
? LinearProgressIndicator(
|
|
|
|
value: progress / 100,
|
|
...
|
...
|
@@ -604,7 +588,12 @@ class _ExportBookDataPageState extends State<ExportBookDataPage> { |
|
|
|
await customerProvider.getExportInfo(context, pramas);
|
|
|
|
if (success) {
|
|
|
|
//成功
|
|
|
|
_download();
|
|
|
|
if (customerProvider.exportInfoSunModel.list.length == 0) {
|
|
|
|
Utils.showToast('当前时间段内没有预订数据!');
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
_download();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// String title = Platform.isAndroid ? '存储' : '相册';
|
...
|
...
|
|