getObjects<T extends VasatModel<T>> method

  1. @override
Future<List<T>> getObjects<T extends VasatModel<T>>(
  1. VasatFromJsonFactory<T> factory
)
override

Implementation

@override
Future<List<T>> getObjects<T extends VasatModel<T>>(VasatFromJsonFactory<T> factory) {
  // use factory to construct empty object just to get the vasat object name.
  var vasatObjectName = factory({}).getObjectName();
  return SharedPreferences.getInstance().then((prefs) {
    var stringObjs = prefs.getString( vasatObjectName );
    Map<String, dynamic> mapObjs = {};
    if (stringObjs != null) mapObjs = jsonDecode(stringObjs);
    List<T> objList = mapObjs.entries.map((ele) => factory(ele.value) ).toList();
    return objList;
  });
}