Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow a search parameter on getCards() #8

Open
wants to merge 6 commits into
base: dev
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
maybe error handling?
  • Loading branch information
JayHors committed Dec 8, 2022
commit 6648d13daa840ffbbd56fc63cebae967661a10a2
6 changes: 5 additions & 1 deletion lib/src/pokemon_tcg.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'dart:convert';
import 'dart:isolate';

import 'package:http/http.dart' as http;
import 'package:pokemon_tcg/src/models/card.dart';
Expand All @@ -21,7 +22,7 @@ class PokemonTcgApi {
static const _baseUrl = 'https://api.pokemontcg.io/v2';
static const _setsUrl = '$_baseUrl/sets';

/// Gets a paginated list of all pokemon cards.
/// Gets a paginated list of all pokemon cards by default, with an optional search parameter.
Future<List<PokemonCard>> getCards({
int page = 0,
String query = '',
Expand All @@ -44,6 +45,9 @@ class PokemonTcgApi {
}

JsonMap json = jsonDecode(response.body);
if (json['error']) {
throw RemoteError('Invalid search parameter', json['error']);
}
final cards = <PokemonCard>[];
List<dynamic> cardsJson = json['data'];
cardsJson.forEach((element) {
Expand Down