Files
TtxPageAdmin/lib/platform/studio_download_saver_io.dart
T
2026-05-16 01:10:06 +08:00

25 lines
660 B
Dart

import 'dart:io';
import 'dart:typed_data';
import 'package:file_selector/file_selector.dart';
// 桌面端保存下载文件:打开系统“另存为”对话框并落盘。
Future<String?> saveBytesToFile({
required Uint8List bytes,
required String suggestedName,
}) async {
final location = await getSaveLocation(
suggestedName: suggestedName,
acceptedTypeGroups: <XTypeGroup>[
XTypeGroup(label: 'Zip', extensions: <String>['zip']),
],
);
final path = location?.path;
if (path == null || path.trim().isEmpty) {
return null;
}
final file = File(path);
await file.writeAsBytes(bytes, flush: true);
return path;
}