在抖动中使用dio进行缓存

时间:2020-08-25 09:08:24

标签: flutter dio

我的.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;
        }
    }

0 个答案:

没有答案