This is a Dart (and Flutter) client for PokeApi.
Table of Contents
1. Depend on it
Add this to your package's pubspec.yaml file:
dependencies:
pokeapi_dart: ^[latest_version]
2. Install it
You can install packages from the command line:
with Flutter:
$ flutter pub get
Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.
3. Import it
Now in your Dart code, you can use:
import 'package:pokeapi_dart/pokeapi_dart.dart';
import 'package:pokeapi_dart/pokeapi_dart.dart';
final api = PokeApi();
import 'package:pokeapi_dart/pokeapi_dart.dart';
void main() async {
final api = PokeApi();
// with await, be sure to be in an async function (and in a try/catch)
final golduck = await api.pokemon.get(name: 'golduck');
print(golduck);
// with Future
api.pokemon.get(name: 'eevee').then((response) {
print(response);
});
// get pokemon by id
final firstPokemon = api.pokemon.get(id: 1);
print(firstPokemon);
}
The pokeapi_dart does not support any features for http request.
If you only want to change the http client, pass the customized client to the factory of PokeApiClient. PokeApiClient handles the request and DTO parsing. If you want to change the whole thing, use a class that extends PokeApiClient to create PokeApi.
final customClientApi = PokeApi(
client: PokeApiClient(
client: CustomHttpClient(), // opt
converterFactory: CustomConverterFactory(), // opt
),
);
final customPokeApiClientApi = PokeApi(client: CustomPokeApiClient());
pokeapi_dart
can be tested using Dart.
pub run test
The get method can use id
or id or name
as a parameter according to each endpoint type.
Refer to the pokeapi v2 docs to find out more about how the data is structured.
Use berries to return data about a specific berry.
PokeApi().berries.get(name: 'cheri').then((response) {
print(response);
});
Use berryFirmness to return data about the firmness of a specific berry.
PokeApi().berryFirmness.get(name: 'very-soft').then((response) {
print(response);
});
Use berryFlavors to return data about the flavor of a specific berry.
PokeApi().berryFlavors.get(name: 'spicy').then((response) {
print(response);
})
Use contestTypes to return data about the effects of moves when used in contests.
PokeApi().contestTypes.get(name: 'cool').then((response) {
print(response);
})
Use contestEffects to return data about the effects of moves when used in contests.
PokeApi().contestEffects.get(id: 1).then((response) {
print(response);
})
Use superContestEffects to return data about the effects of moves when used in super contests.
PokeApi().superContestEffects.get(id: 1).then((response) {
print(response);
})
Use encounterMethods to return data about the conditions in which a trainer may encounter a pokemon in the wild.
PokeApi().encounterMethods.get(name: 'walk').then((response) {
print(response);
})
Use encounterConditions to return data that affects which pokemon might appear in the wild.
PokeApi().encounterConditions.get(name: 'swarm').then((response) {
print(response);
})
Use encounterConditionValues to return data the various states that an encounter condition can have.
PokeApi().encounterConditionValues.get(name: 'swarm-yes').then((response) {
print(response);
})
Use evolutionChains to return data evolution chains.
PokeApi().evolutionChains.get(id: 1).then((response) {
print(response);
})
Use evolutionTriggers to return data about triggers which cause pokemon to evolve.
PokeApi().evolutionTriggers.get(name: 'level-up').then((response) {
print(response);
})
Use generations to return data about the different generations of pokemon games.
PokeApi().generations.get(name: 'generation-i').then((response) {
print(response);
})
Use pokedexes to return data about specific types of pokedexes.
PokeApi().pokedexes.get(name: 'kanto').then((response) {
print(response);
})
Use version to return data about specific versions of pokemon games.
PokeApi().version.get(name: 'red').then((response) {
print(response);
})
Use versionGroups to return data about specific version groups of pokemon games.
PokeApi().versionGroups.get(name: 'red'blue").then((response) {
print(response);
})
Use item to return data about specific items.
PokeApi().item.get(name: 'master-ball').then((response) {
print(response);
})
Use itemAttributes to return data about specific item attribute.
PokeApi().itemAttributes.get(name: 'countable').then((response) {
print(response);
})
Use itemCategories to return data about specific item category.
PokeApi().itemCategories.get(name: 'stat-boosts').then((response) {
print(response);
})
Use itemFlingEffects to return data about specific item fling effect.
PokeApi().itemFlingEffects.get(name: 'badly-poison').then((response) {
print(response);
})
Use itemPockets to return data about specific pockets in a players bag.
PokeApi().itemPockets.get(name: 'misc').then((response) {
print(response);
})
Use machines to return data about specific machine.
PokeApi().machines.get(id: 2).then((response) {
print(response);
})
Use moves to return data about specific pokemon move.
PokeApi().moves.get(name: 'pound').then((response) {
print(response);
})
Use moveAilments to return data about specific pokemon move ailment.
PokeApi().moveAilments.get(name: 'paralysis').then((response) {
print(response);
})
Use moveBattleStyles to return data about specific pokemon move battle style.
PokeApi().moveBattleStyles.get(name: 'attack').then((response) {
print(response);
})
Use moveCategories to return data about specific pokemon move category.
PokeApi().moveCategories.get(name: 'ailment').then((response) {
print(response);
})
Use moveDamageClasses to return data about specific pokemon damage class.
PokeApi().moveDamageClasses.get(name: 'status').then((response) {
print(response);
})
Use moveLearnMethods to return data about specific pokemon learn method.
PokeApi().moveLearnMethods.get(name: 'level-up').then((response) {
print(response);
})
Use moveTargets to return data about specific pokemon move target.
PokeApi().moveTargets.get(name: 'specific-move').then((response) {
print(response);
})
Use locations to return data about specific pokemon location.
PokeApi().locations.get(name: 'sinnoh').then((response) {
print(response);
})
Use locationAreas to return data about specific pokemon location area.
PokeApi().locationAreas.get(name: 'canalave-city-area').then((response) {
print(response);
})
Use palParkAreas to return data about specific pokemon pal park area.
PokeApi().palParkAreas.get(name: 'forest').then((response) {
print(response);
})
Use regions to return data about specific pokemon region.
PokeApi().regions.get(name: 'kanto').then((response) {
print(response);
})
Use itemAttributes to return data about specific pokemon ability.
PokeApi().itemAttributes.get(name: 'stench').then((response) {
print(response);
})
Use characteristics to return data about specific pokemon characteristic.
PokeApi().characteristics.get(id: 1).then((response) {
print(response);
})
Use eggGroups to return data about specific pokemon egg group.
PokeApi().eggGroups.get(name: 'monster').then((response) {
print(response);
})
Use genders to return data about specific pokemon gender.
PokeApi().genders.get(name: 'female').then((response) {
print(response);
})
Use growthRates to return data about specific pokemon growth rate.
PokeApi().growthRates(name: 'slow').then((response) {
print(response);
})
Use natures to return data about specific pokemon nature.
PokeApi().natures.get(name: 'bold').then((response) {
print(response);
})
Use pokeathlonStats to return data about specific pokeathon stat.
PokeApi().pokeathlonStats.get(name: 'speed').then((response) {
print(response);
})
Use pokemon to return data about specific pokemon.
PokeApi().pokemon.get(name: 'butterfree').then((response) {
print(response);
})
Use pokemonColors to return data about specific pokemon color.
PokeApi().pokemonColors.get(name: 'black').then((response) {
print(response);
})
Use pokemonForms to return data about specific pokemon form.
PokeApi().pokemonForms.get(name: 'wormadam-plant').then((response) {
print(response);
})
Use pokemonHabitats to return data about specific pokemon habitat.
PokeApi().pokemonHabitats.get(name: 'grottes').then((response) {
print(response);
})
Use pokemonShapes to return data about specific pokemon shape.
PokeApi().pokemonShapes.get(name: 'ball').then((response) {
print(response);
})
Use pokemonSpecies to return data about specific pokemon species.
PokeApi().pokemonSpecies.get(name: 'wormadam').then((response) {
print(response);
})
Use stats to return data about specific pokemon stat.
PokeApi().stats.get(name: 'attack').then((response) {
print(response);
})
Use types to return data about specific pokemon type.
PokeApi().types.get(name: 'ground').then((response) {
print(response);
})
Use languages to return data about specific pokemon language.
PokeApi().languages(name: 'ko').then((response) {
print(response);
})
Each endpoint provide a getPage
method to get paged items contained by that endpoint.
It can configure offset and limit.
offset
is where to start. The first item that you will get. Default0
limit
is how many items you want to list. Default20
This call will get the list of Pokémon between ID 35 and ID 44
PokeApi().pokemon.getPage(offset: 34, limit 10).then((response) {
print(response);
})
This is what you will get:
{
"count": 1118,
"next": "https://pokeapi.co/api/v2/pokemon/?offset=44&limit=10",
"previous": "https://pokeapi.co/api/v2/pokemon/?offset=24&limit=10",
"results": [
{
"name": "nidoking",
"url": "https://pokeapi.co/api/v2/pokemon/34/"
},
{
"name": "clefairy",
"url": "https://pokeapi.co/api/v2/pokemon/35/"
},
{
"url": "...",
"name": "..."
},
{
"name": "golbat",
"url": "https://pokeapi.co/api/v2/pokemon/42/"
},
{
"name": "oddish",
"url": "https://pokeapi.co/api/v2/pokemon/43/"
}
]
}