File tree 2 files changed +32
-2
lines changed
2 files changed +32
-2
lines changed Original file line number Diff line number Diff line change 1
1
import 'dart:async' ;
2
- import 'package:meta/meta.dart' ;
3
2
4
3
import 'package:hive/hive.dart' ;
4
+ import 'package:meta/meta.dart' ;
5
5
6
6
import './store.dart' ;
7
7
@@ -92,7 +92,15 @@ class HiveStore extends Store {
92
92
}
93
93
94
94
@override
95
- Map <String , Map <String , dynamic >?> toMap () => Map .unmodifiable (box.toMap ());
95
+ Map <String , Map <String , dynamic >?> toMap () {
96
+ final map = < String , Map <String , dynamic >? > {};
97
+ for (final key in box.keys) {
98
+ if (key is String ) {
99
+ map[key] = get (key);
100
+ }
101
+ }
102
+ return Map .unmodifiable (map);
103
+ }
96
104
97
105
Future <void > reset () => box.clear ();
98
106
}
Original file line number Diff line number Diff line change @@ -121,6 +121,28 @@ void main() {
121
121
expect (readData2? ['bob' ], isA <List <dynamic >>());
122
122
expect (readData2? ['bob' ][0 ], isA <Map <String , dynamic >>());
123
123
});
124
+ test ("Can re-open and reference nested data" , () async {
125
+ final box1 = await HiveStore .openBox (
126
+ 're-open-store' ,
127
+ path: path,
128
+ );
129
+ final store = HiveStore (box1);
130
+ final data = {
131
+ 'foo' : 'bar' ,
132
+ 'bob' : [
133
+ {'nested' : true }
134
+ ]
135
+ };
136
+ store.put ("id" , data);
137
+ expect (store.toMap (), equals ({'id' : data}));
138
+ await box1.close ();
139
+ final box2 = await HiveStore .openBox (
140
+ 're-open-store' ,
141
+ path: path,
142
+ );
143
+ final store2 = HiveStore (box2);
144
+ expect (store2.toMap (), equals ({'id' : data}));
145
+ });
124
146
test ("Can put null" , () async {
125
147
final box1 = await HiveStore .openBox (
126
148
'put-null' ,
You can’t perform that action at this time.
0 commit comments