loadAsObj method

Future<Map<String, dynamic>?> loadAsObj()

Same as load, but expects the file to be a Map<String, dynamic> representing a single object. Will fail if it's not a map. It may return null.

Implementation

Future<Map<String, dynamic>?> loadAsObj() async {
  Object? simpleObj = await load();
  if (simpleObj == null) return null;
  if (simpleObj is! Map<String, dynamic>) throw PersistException("Not an object: $simpleObj");
  return simpleObj;
}