Last active
November 19, 2020 02:04
-
-
Save EduardoReisDev/4602af597e6ac501ad87069f71ba697c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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