25 lines
650 B
Dart
25 lines
650 B
Dart
import 'dart:convert';
|
|
import 'dart:typed_data';
|
|
|
|
import 'package:file_picker/file_picker.dart';
|
|
|
|
class BackupFileService {
|
|
Future<bool> save(String json, String name) async =>
|
|
await FilePicker.saveFile(
|
|
dialogTitle: 'Datensicherung speichern',
|
|
fileName: name,
|
|
bytes: Uint8List.fromList(utf8.encode(json)),
|
|
) !=
|
|
null;
|
|
|
|
Future<String?> open() async {
|
|
final file = await FilePicker.pickFile(
|
|
dialogTitle: 'Datensicherung auswählen',
|
|
type: FileType.custom,
|
|
allowedExtensions: ['json'],
|
|
);
|
|
if (file == null) return null;
|
|
return utf8.decode(await file.readAsBytes());
|
|
}
|
|
}
|