- 新建 file_download.dart 跨平台下载工具(conditional import) - download_impl_web.dart: Web 平台通过 html.AnchorElement + Blob 下载 - download_impl.dart: 非 Web 平台 stub(Phase 2 扩展 path_provider) - _ExportDataView: 添加下载按钮 + JSON 折叠预览 + PIPL 提示 - 移除 'Phase 1 预览' 占位文案,替换为完整下载功能
24 lines
682 B
Dart
24 lines
682 B
Dart
// 文件下载工具 — 跨平台接口
|
||
//
|
||
// Web: 通过 html.AnchorElement + Blob 触发浏览器下载
|
||
// 非 Web: 返回 false(Phase 2 扩展 path_provider)
|
||
|
||
import 'dart:convert';
|
||
|
||
import 'download_impl.dart'
|
||
if (dart.library.html) 'download_impl_web.dart';
|
||
|
||
/// 下载 JSON 数据为文件
|
||
///
|
||
/// [data] — 要导出的 JSON 数据
|
||
/// [filename] — 下载文件名(如 "export_2026-06-02.json")
|
||
///
|
||
/// 返回 true 表示下载成功。
|
||
Future<bool> downloadJsonFile(
|
||
Map<String, dynamic> data,
|
||
String filename,
|
||
) async {
|
||
final jsonStr = const JsonEncoder.withIndent(' ').convert(data);
|
||
return downloadFile(jsonStr, filename, 'application/json');
|
||
}
|