Skip to content

Instantly share code, notes, and snippets.

@EduardoReisDev
Last active November 19, 2020 02:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EduardoReisDev/4602af597e6ac501ad87069f71ba697c to your computer and use it in GitHub Desktop.
Save EduardoReisDev/4602af597e6ac501ad87069f71ba697c to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using Pokedex.Services;
using Refit;
using Xamarin.Forms;
namespace Pokedex.View
{
public partial class BuscarPokemon : ContentPage
{
public BuscarPokemon()
{
InitializeComponent();
button_pokemon.Clicked += BuscarPokemonAPI;
}
private async void BuscarPokemonAPI(object sender, EventArgs args)
{
String pokemon = entry_pokemon.Text.Trim().ToLower();
try
{
var apiClient = RestService.For<IPokemonAPI>(CaminhoBaseAPI.BaseUrl);
var pokemonnome = await apiClient.GetPokemonAsync(pokemon);
float resultHeight = (float) pokemonnome.Height / (float) 10;
float resultWeight = (float)pokemonnome.Weight / (float) 10;
id_pokemon.Text = string.Format($"ID: {pokemonnome.Id}");
nome_pokemon.Text = string.Format($"Nome: {pokemonnome.Name}");
altura_pokemon.Text = string.Format($"Altura: {resultHeight} m");
peso_pokemon.Text = string.Format($"Peso: {resultWeight} kg");
experiencia_pokemon.Text = string.Format($"Experiência Base: {pokemonnome.Base_experience}");
imagem.Source = string.Format($"https://pokeres.bastionbot.org/images/pokemon/{pokemonnome.Id}.png");
}
catch(Exception e)
{
Console.WriteLine("Erro na consulta do Pokemon: " + e.Message);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment