getCardByNameAsImage method
Future<Uint8List>
getCardByNameAsImage(
- String name, {
- SearchType searchType = SearchType.exact,
- String? set,
- bool? backFace,
- ImageVersion? imageVersion,
GET /cards/named?format=image
Returns an image of a Card based on a name search string. This method is designed for building chat bots, forum bots, and other services that need card details quickly.
name
: The name to search for.
searchType
: The type of search that shall be executed
by the server. SearchType.exact performs a search that
returns a card with the exact name
. SearchType.fuzzy
performs a fuzzy search.
Defaults to SearchType.exact.
set
: A set code to limit the search to one set.
backFace
: If true
, the back face of the card is returned.
Will return a 422 if this card has no back face.
Defaults to false
.
imageVersion
: The version of the image that shall
be returned.
Defaults to ImageVersion.large.
Implementation
Future<Uint8List> getCardByNameAsImage(
String name, {
SearchType searchType = SearchType.exact,
String? set,
bool? backFace,
ImageVersion? imageVersion,
}) async {
final url = Uri.https(
_baseUrl,
'/cards/named',
<String, String?>{
'format': 'image',
'exact': searchType == SearchType.exact ? name : null,
'fuzzy': searchType == SearchType.fuzzy ? name : null,
'set': set,
'face': backFace == true ? 'back' : null,
'version': imageVersion?.json,
}..removeWhere((_, value) => value == null),
);
final response = await _httpClient.get(url);
if (response.statusCode != 200) {
final json = jsonDecode(response.body) as Map<String, dynamic>;
throw ScryfallException.fromJson(json);
}
return response.bodyBytes;
}