flutter: Cannot copy hive dile to storage by file.copy
- Dominant language
- Dart
- Stars
- 4.4k
- Forks
- 449
- PR merge metrics
- No merged PRs in 30d
Description
I am trying to copy hive box to my mobile storage. After acception sufficient permissions, I run my method:
Future exportVocabsDb() async {
final dir = await getExternalStorageDirectory();
final evbDirectory =
await Directory('${dir!.path}/evb').create(recursive: true);
hiveService.backupHiveBox(
VOCABULARY_BOX, evbDirectory.path);
}
and :
Future backupHiveBox(String boxName, String backupPath) async {
if (!Hive.isBoxOpen(boxName)) {}
final box = await Hive.openBox(boxName);
final boxPath = box.path;
await box.close();
try {
File(boxPath!).copy(backupPath);
} finally {
await Hive.openBox(boxName);
}
}
But I got this error:
` E/flutter (14955): [ERROR:flutter/lib/ui/ui_dart_state.cc(199)] Unhandled Exception: FileSystemException: Cannot copy file to '/storage/emulated/0/Android/data/com.example.english_vocabulary_builder/files/evb', path = '/data/user/0/com.example.english_vocabulary_builder/app_flutter/vocabularybox.hive' (OS Error: Is a directory, errno = 21)`
There is hive file inside app_flutter :
https://pasteboard.co/KdI1Juxp.png
this is doctor:
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 2.2.3, on Linux, locale en_US.UTF-8)
[!] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
✗ Android license status unknown.
Run `flutter doctor --android-licenses` to accept the SDK licenses.
See https://flutter.dev/docs/get-started/install/linux#android-setup for more details.
[✓] Chrome - develop for the web
[✓] Android Studio (version 4.2)
[✓] Android Studio
[✓] VS Code (version 1.58.2)
[✓] Connected device (2 available)
! Doctor found issues in 1 category.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.