File tree Expand file tree Collapse file tree 2 files changed +32
-2
lines changed Expand file tree Collapse file tree 2 files changed +32
-2
lines changed Original file line number Diff line number Diff line change 11import 'dart:async' ;
2- import 'package:meta/meta.dart' ;
32
43import 'package:hive/hive.dart' ;
4+ import 'package:meta/meta.dart' ;
55
66import './store.dart' ;
77
@@ -92,7 +92,15 @@ class HiveStore extends Store {
9292 }
9393
9494 @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+ }
96104
97105 Future <void > reset () => box.clear ();
98106}
Original file line number Diff line number Diff line change @@ -121,6 +121,28 @@ void main() {
121121 expect (readData2? ['bob' ], isA <List <dynamic >>());
122122 expect (readData2? ['bob' ][0 ], isA <Map <String , dynamic >>());
123123 });
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+ });
124146 test ("Can put null" , () async {
125147 final box1 = await HiveStore .openBox (
126148 'put-null' ,
You can’t perform that action at this time.
0 commit comments