Created
January 13, 2021 19:33
-
-
Save Emeka-Chukwu/a8733547fe93376c9ba0c48796f1fc4f 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
import 'dart:convert'; | |
import 'package:flutter/material.dart'; | |
import 'package:http/http.dart' as http; | |
import 'package:pokemonApp/pokemon.dart'; | |
import 'package:pokemonApp/pokemondetails.dart'; | |
void main()=>runApp(MaterialApp( | |
title:"poke App", | |
home: HomePage(), | |
debugShowCheckedModeBanner: false, | |
)); | |
class HomePage extends StatefulWidget { | |
@override | |
_HomePageState createState() => _HomePageState(); | |
} | |
class _HomePageState extends State<HomePage> { | |
var url ="https://raw.githubusercontent.com/Biuni/PokemonGO-Pokedex/master/pokedex.json"; | |
PokeHub pokeHub; | |
@override | |
void initState(){ | |
super.initState(); | |
fetchData(); | |
} | |
fetchData() async{ | |
var res = await http.get(url); | |
print(res.body); | |
var emeka = jsonDecode(res.body); | |
pokeHub = PokeHub.fromJson(emeka); | |
setState(() { | |
}); | |
} | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: Text("Poke App"), | |
backgroundColor: Colors.cyan | |
), | |
body: pokeHub == null ? | |
Center(child: CircularProgressIndicator()): | |
GridView.count( | |
crossAxisCount: 2, | |
children: pokeHub.pokemon.map((poke) => Padding( | |
padding: const EdgeInsets.all(8.0), | |
child: InkWell( | |
onTap: (){ | |
Navigator.push(context, MaterialPageRoute(builder: (context) => PokeDetail(pokemon: poke))); | |
}, | |
child: Hero( | |
tag: poke.img, | |
child: Card( | |
elevation: 3.0, | |
child: Column( | |
mainAxisAlignment: MainAxisAlignment.spaceEvenly, | |
children: [ | |
Container( | |
height: 100, | |
width: 100, | |
decoration: BoxDecoration( | |
image: DecorationImage( | |
image: NetworkImage(poke.img) | |
) | |
), | |
), | |
Text(poke.name, style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold),) | |
] | |
), | |
), | |
), | |
), | |
)).toList(),), | |
floatingActionButton: FloatingActionButton(onPressed: null,child: Icon(Icons.refresh), | |
backgroundColor: Colors.cyan, | |
), | |
drawer: Drawer(), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment