我的.googlePlacesUrlFromId
呼叫了Google api场所。我想知道缓存响应的最佳方法是什么?我可以检查一下placesId
是否有数据吗?您如何检查Dio响应中是否有数据?
Future<Venue> getVenueById(String venueId) async {
if (currentVenues != null && currentVenues.isNotEmpty) {
var venueFromCache = currentVenues.firstWhere((venue) => venue.id == venueId, orElse: () => null);
if (venueFromCache != null) {
return venueFromCache;
}
}
var venueDocument = await _venuesCollectionReference.document(venueId).get();
var menus = await getMenusForVenueId(venueDocument.documentID);
var venue = Venue.fromFirebase(venueDocument, menus);
if (venue.place?.placeId != null && venue.place.placeId.isNotEmpty) {
var placesId = await Dio().get(SchnapConfigValues.googlePlacesUrlFromId(venue.place.placeId, "formatted_address"));
venue.formattedAddress = placesId.data["result"]["formatted_address"];
return venue;
} else {
venue.formattedAddress = "";
return venue;
}
}