Last active
May 12, 2021 22:51
-
-
Save ramyak-mehra/ddf6123ed50be501f175fc010c452e2c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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