Notes & TILs
Search…
Get all Hive 🐝 boxes
Posted on 05 Jan, 2022
1
import 'dart:async';
2
import 'dart:io';
3
​
4
import 'package:hive/hive.dart';
5
import 'package:path_provider/path_provider.dart';
6
import 'package:path/path.dart' as p;
7
​
8
extension on HiveInterface {
9
/// Get a name list of existing boxes
10
FutureOr<List<String>> getNamesOfBoxes() async {
11
final appDir = await getApplicationDocumentsDirectory();
12
var files = appDir.listSync();
13
var _list = <String>[];
14
​
15
files.forEach((file) {
16
if (file.statSync().type == FileSystemEntityType.file
17
&& p.extension(file.path).toLowerCase() == '.hive') {
18
_list.add(p.basenameWithoutExtension(file.path));
19
}
20
});
21
print('Current boxes: $_list');
22
return _list;
23
}
24
}
Copied!

Resources

Last modified 13d ago
Copy link
Contents
Resources