getRandomCard method
GET /cards/random
Returns a single random MtgCard
object.
query
: Is used to filter the possible cards
and return a random card from the resulting pool
of cards. Supports the same
fulltext search system
as the main site.
Implementation
Future<MtgCard> getRandomCard({String? query}) async {
final url = Uri.https(
_baseUrl,
'/cards/random',
<String, String?>{
'q': query,
}..removeWhere((_, value) => value == null),
);
final response = await _httpClient.get(url);
final json = jsonDecode(response.body) as Map<String, dynamic>;
if (response.statusCode != 200) {
throw ScryfallException.fromJson(json);
}
return MtgCard.fromJson(json);
}