load method
Loads typed data for the given context.
Implementation
@override
Future<DataProviderResult<T>> load(RouteDataContext context) async {
final docId =
context.parameters[idParam] ?? context.queryParameters[idParam];
if (docId == null || docId.isEmpty) {
return DataProviderResult<T>.notFound();
}
final snapshot = await fetcher(collection, docId);
if (snapshot == null) {
return DataProviderResult<T>.notFound();
}
if (snapshot['is_deleted'] == true) {
return DataProviderResult<T>.gone(
cacheTags: [collection, '$collection:$docId'],
);
}
final entity = mapper(docId, snapshot);
DateTime? updatedAt;
if (snapshot['updated_at'] is DateTime) {
updatedAt = snapshot['updated_at'] as DateTime;
} else if (snapshot['updated_at'] is String) {
updatedAt = DateTime.tryParse(snapshot['updated_at'] as String);
}
final etag = snapshot['version'] != null
? 'w/"${snapshot['version']}"'
: null;
return DataProviderResult<T>.found(
entity,
lastModified: updatedAt,
etag: etag,
cacheTags: [collection, '$collection:$docId'],
);
}