refactor(programs): 模板保存目录改为下载目录
- getDownloadsDirectory() 优先,失败时回退到应用文档目录 - 更新 dartdoc 说明
This commit is contained in:
@@ -18,11 +18,13 @@ class ExcelTemplateService {
|
|||||||
static const String sheetPrograms = 'Programs';
|
static const String sheetPrograms = 'Programs';
|
||||||
static const String sheetSteps = 'Steps';
|
static const String sheetSteps = 'Steps';
|
||||||
|
|
||||||
/// 生成模板并保存到应用文档目录,返回文件对象
|
/// 生成模板并保存到下载目录,返回文件对象
|
||||||
|
///
|
||||||
|
/// 优先使用系统下载目录;不支持时回退到应用文档目录。
|
||||||
Future<File> generateTemplate() async {
|
Future<File> generateTemplate() async {
|
||||||
final excel = Excel.createExcel();
|
final excel = Excel.createExcel();
|
||||||
final bytes = _buildTemplateBytes(excel);
|
final bytes = _buildTemplateBytes(excel);
|
||||||
final dir = await getApplicationDocumentsDirectory();
|
final dir = await getDownloadsDirectory() ?? await getApplicationDocumentsDirectory();
|
||||||
final file = File('${dir.path}/program_template.xlsx');
|
final file = File('${dir.path}/program_template.xlsx');
|
||||||
await file.writeAsBytes(bytes, flush: true);
|
await file.writeAsBytes(bytes, flush: true);
|
||||||
return file;
|
return file;
|
||||||
|
|||||||
Reference in New Issue
Block a user