jonataslaw / get_storage

A fast, extra light and synchronous key-value storage to Get framework
MIT License
359 stars 82 forks source link

Diffirent type in each time read storage #57

Open vuaavan opened 3 years ago

vuaavan commented 3 years ago

I have 2 model : House and Room with 4 screen with tree map List house > Edit house > List room > Edit room / Add room . Problem happens with List room screen. In List room controller, I get list all room with : List rooms = GetStorage().read<List>('rooms'); In first time, while start app, I go to List room screen, result of rooms is List of Map, like : [{id: 1, name: Alpha Room, totalPeople: 1, floor: 1}, {id: 2, name: Beta Room, totalPeople: 2, floor: 1} ....]

but, if I add a new room and save to storage GetStorage().write('rooms', rooms.toList()); and go back screen Edit house and to screen List room again, i got list of instance of Room.

What is diffirent in 2 situation ?

_flutter 2 get: ^3.26.0 getstorage: ^1.4.0

aminkhan1 commented 3 years ago

i had this problem. i fix this problem like this if (store.read('docs') is DocsModel) { return model = store.read('docs'); } else { return model = DocsModel.fromJson(store.read('docs')); }

Apollo108 commented 3 years ago

@vuaavan I also had this problem, I just encode my list into a string and decode it later, respectively:

`
final localResults = GetStorage().read(StorageKeys.alertCheckResults);

  if (localResults != null) {
    final decodedData = json.decode(localResults as String);
    combinedResults.addAll(
      (decodedData as List<dynamic>).map((el) => AlertCheckResult.fromMap(el as Map<String, dynamic>)),
    );
  }

  GetStorage().write(StorageKeys.alertCheckResults, json.encode(combinedResults.map((el) => el.toMap()).toList()));

`