Skip to content

Instantly share code, notes, and snippets.

@ramyak-mehra
Last active May 12, 2021 22:51
Show Gist options
  • Select an option

  • Save ramyak-mehra/ddf6123ed50be501f175fc010c452e2c to your computer and use it in GitHub Desktop.

Select an option

Save ramyak-mehra/ddf6123ed50be501f175fc010c452e2c to your computer and use it in GitHub Desktop.
class Home extends StatelessWidget {
final ArtemisClient artemisClient;
const Home({Key? key, required this.artemisClient}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
appBar: AppBar(
title: Text('Pokedex'),
),
body: FutureBuilder(
future: _fetchArtemisClient(artemisClient),
builder: (BuildContext context,
AsyncSnapshot<FetchPokemons$Query> snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return Center(child: CircularProgressIndicator());
} else if (snapshot.hasError) {
return Center(
child: Text(snapshot.error.toString()),
);
} else if (snapshot.data != null) {
final pokemons = snapshot.data!.pokemons;
return ListView.builder(
itemCount: pokemons!.length,
itemBuilder: (context, index) {
final pokemon = pokemons[index]!;
return ExpansionTile(
trailing: Icon(Icons.arrow_drop_down_sharp),
title: Text(pokemon.name ?? 'pokemon name'),
subtitle: Text(
pokemon.classification ?? 'pokemon classification'),
leading: Image.network(pokemon.image!),
children: [
ListTile(
title: Text('Max HP'),
subtitle: Text(pokemon.maxHP.toString()),
),
ListTile(
title: Text('Max CP'),
subtitle: Text(pokemon.maxCP.toString()),
),
],
);
});
}
return Center(
child: Text('Error fetching data'),
);
}),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment