save static method
保存文件
bytes 要保存的字节数据
filePath 文件保存路径
返回是否保存成功
Implementation
static Future<bool> save({
required List<int> bytes,
required String filePath,
}) async {
if (bytes.isEmpty || filePath.isEmpty || kIsWeb) {
return false;
}
try {
final fileName = path.basename(filePath);
final dirPath = filePath.replaceAll(fileName, '');
// 确保目录存在
final pathCreated = await createPath(path: dirPath);
if (!pathCreated) {
return false;
}
final file = File(filePath);
await file.writeAsBytes(bytes, flush: true);
return true;
} catch (e) {
developer.log('保存文件失败: $e');
return false;
}
}