getPlainPhotoUrl method
Get the photo url of a Place after redirect, this means the final photo url will not use the apiKey nor the place or photo id.
Required params:
nameorplaceIdandphotoId: If you opt to useplaceIdandphotoId, set only the ids without the resource name.maxWidthPxormaxHeightPx: You can specify one or both to set the the maximum desired height and width pixels of the image.
Documentation: https://developers.google.cn/maps/documentation/places/web-service/place-photos#get-photo-ref
Implementation
Future<GoogleHTTPResponse<String>> getPlainPhotoUrl({
/// Photo resource name: https://developers.google.cn/maps/documentation/places/web-service/place-photos#photo-name
String? name,
/// Place identifier
String? placeId,
/// Photo identifier
String? photoId,
/// Maximum desired width of the image in pixels: https://developers.google.cn/maps/documentation/places/web-service/place-photos#maxheightpx-and-maxwidthpx
int? maxWidthPx,
/// Maximum desired height of the image in pixels: https://developers.google.cn/maps/documentation/places/web-service/place-photos#maxheightpx-and-maxwidthpx
int? maxHeightPx,
/// Used to cancel the request, if not specified, the default [cancelToken] of the [PlacesAPINew] will be used.
CancelToken? cancelToken,
}) async {
final requestOptions = RequestOptions(
method: 'GET',
baseUrl: _buildPhotoUrl(
name: name,
placeId: placeId,
photoId: photoId,
maxWidthPx: maxWidthPx,
maxHeightPx: maxHeightPx,
skipHttpRedirect: true,
),
responseType: ResponseType.json,
receiveTimeout: restAPI.receiveTimeout,
connectTimeout: restAPI.connectTimeout,
sendTimeout: restAPI.sendTimeout,
cancelToken: cancelToken ?? restAPI.cancelTokenCallback?.call(),
);
final response = await restAPI.dio.fetch<Map<String, dynamic>>(
requestOptions,
);
late Photo? photo = response.data == null
? null
: Photo.fromJson(response.data!);
return GoogleHTTPResponse(
http.Response(
'',
response.statusCode ?? 404,
headers: MapUtils.parseHeaders(response.headers) ?? {},
isRedirect: response.isRedirect,
request: http.Request(
response.requestOptions.method,
response.requestOptions.uri,
),
),
photo?.photoUri,
extraData: response.extra,
error: response.statusCode != 200
? GoogleErrorResponse(
error: ErrorInfo(message: 'Failed to fetch photo binary'),
)
: null,
);
}