Some checks failed
Release / meta (push) Successful in 18s
Release / android-build (push) Successful in 11m48s
Release / linux-build (push) Successful in 1m24s
Release / web-build (push) Successful in 6m15s
Release / release-dev (push) Has been cancelled
Release / release-master (push) Has been cancelled
30 lines
742 B
Dart
30 lines
742 B
Dart
import 'dart:typed_data';
|
|
|
|
import 'package:file_selector/file_selector.dart';
|
|
|
|
class SaveResult {
|
|
final String? path;
|
|
final bool canceled;
|
|
|
|
const SaveResult({this.path, required this.canceled});
|
|
}
|
|
|
|
Future<SaveResult> saveBytes(
|
|
Uint8List bytes,
|
|
String filename, {
|
|
String? mimeType,
|
|
}) async {
|
|
final safeName = filename.trim().isEmpty ? 'export.bin' : filename.trim();
|
|
final location = await getSaveLocation(suggestedName: safeName);
|
|
if (location == null) {
|
|
return const SaveResult(canceled: true);
|
|
}
|
|
final file = XFile.fromData(
|
|
bytes,
|
|
mimeType: mimeType ?? 'application/octet-stream',
|
|
name: safeName,
|
|
);
|
|
await file.saveTo(location.path);
|
|
return SaveResult(path: location.path, canceled: false);
|
|
}
|