Commit 211c6d219d377e7abd6a8e5fd537d5df85112baf

Authored by wdn127929
1 parent d4d895cb

安卓导出excel

... ... @@ -25,7 +25,11 @@
android:label="周到安排商家"
tools:replace="android:label"
android:icon="@mipmap/ic_launcher">
android:icon="@mipmap/ic_launcher"
android:requestLegacyExternalStorage="true"
android:preserveLegacyExternalStorage="true"
>
<activity
android:name=".MainActivity"
android:exported="true"
... ...
<?xml version="1.0" encoding="utf-8"?>
<!-- <?xml version="1.0" encoding="utf-8"?>
<resources>
<external-path name="external_storage_directory" path="." />
</resources>
\ No newline at end of file
</resources> -->
<paths>
<external-path name="external-path" path="."/>
<external-cache-path name="external-cache-path" path="."/>
<external-files-path name="external-files-path" path="."/>
<files-path name="files_path" path="."/>
<cache-path name="cache-path" path="."/>
<root-path name="root" path="."/>
</paths>
\ No newline at end of file
... ...
... ... @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 50;
objectVersion = 46;
objects = {
/* Begin PBXBuildFile section */
... ... @@ -561,7 +561,7 @@
"$(inherited)",
"$(PROJECT_DIR)/Flutter",
);
MARKETING_VERSION = 6.0.0;
MARKETING_VERSION = 5.2.0;
PRODUCT_BUNDLE_IDENTIFIER = com.naji.reserveLine;
PRODUCT_NAME = Runner;
PROVISIONING_PROFILE_SPECIFIER = "";
... ... @@ -697,7 +697,7 @@
CURRENT_PROJECT_VERSION = 519;
DEVELOPMENT_TEAM = 8J59HM8B82;
ENABLE_BITCODE = NO;
FLUTTER_BUILD_MODE = debug;
FLUTTER_BUILD_MODE = release;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)/Flutter",
... ... @@ -709,7 +709,7 @@
"$(inherited)",
"$(PROJECT_DIR)/Flutter",
);
MARKETING_VERSION = 6.0.0;
MARKETING_VERSION = 5.2.0;
PRODUCT_BUNDLE_IDENTIFIER = com.naji.reserveLine;
PRODUCT_NAME = Runner;
PROVISIONING_PROFILE_SPECIFIER = "";
... ... @@ -745,7 +745,7 @@
"$(inherited)",
"$(PROJECT_DIR)/Flutter",
);
MARKETING_VERSION = 6.0.0;
MARKETING_VERSION = 5.2.0;
PRODUCT_BUNDLE_IDENTIFIER = com.naji.reserveLine;
PRODUCT_NAME = Runner;
PROVISIONING_PROFILE_SPECIFIER = "";
... ...
... ... @@ -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 ? '存储' : '相册';
... ...
... ... @@ -812,7 +812,7 @@ class CustomerProvider extends ChangeNotifier {
getExportInfo(BuildContext context, Map<String, String> params) async {
BaseResp<dynamic> baseResp = await DioUtil()
.request<dynamic>(context, Method.get, HttpUrl.get_export_info,
data: params, showLoading: false)
data: params, showLoading: true)
.catchError((error) {
print(error.toString());
if (error is MyError) {
... ...
... ... @@ -233,7 +233,7 @@ class DialogUtil {
static showAuthorityDestination(
BuildContext context, String name, String title, String subTitle) async {
Timer _timer = Timer(const Duration(seconds: 5), () {
Timer _timer = Timer(const Duration(seconds: 2), () {
// if(!TickerMode.of(context)){
Navigator.of(context).pop(true);
// }
... ...
... ... @@ -456,6 +456,13 @@ packages:
url: "https://pub.flutter-io.cn"
source: hosted
version: "9.1.1"
external_path:
dependency: "direct main"
description:
name: external_path
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.0.3"
fake_async:
dependency: transitive
description:
... ... @@ -566,6 +573,13 @@ packages:
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.0.7"
flutter_filereader:
dependency: "direct main"
description:
name: flutter_filereader
url: "https://pub.flutter-io.cn"
source: hosted
version: "3.0.0"
flutter_image_compress:
dependency: "direct main"
description:
... ... @@ -917,13 +931,13 @@ packages:
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.0.2"
open_file:
open_filex:
dependency: "direct main"
description:
name: open_file
name: open_filex
url: "https://pub.flutter-io.cn"
source: hosted
version: "3.3.2"
version: "4.3.4"
package_config:
dependency: transitive
description:
... ...
... ... @@ -60,6 +60,7 @@ dependencies:
# path_provider: ^1.6.5
# path_provider: ^2.0.10
path_provider: ^2.1.0
external_path: ^1.0.3
## 官方image组件扩展,支持多种图片效果展示
# extended_image: ^1.1.1
# 任意位置访问navigator
... ... @@ -187,7 +188,11 @@ dependencies:
flutter_downloader: ^1.10.5
android_path_provider: ^0.3.0
# open_file: ^3.2.1
open_file: ^3.3.2
# open_file: ^3.3.2
open_filex: ^4.3.4
# open_file_plus: ^3.3.0
flutter_filereader: ^3.0.0
webview_flutter:
path: library/webview_flutter-2.0.13-copy_inappwebview_select_file_20210930
... ...