iampawan / PokemonApp

Pokemon App with animations and beautiful UI
283 stars 126 forks source link

Receiver: null #8

Closed Hemant-7 closed 3 years ago

Hemant-7 commented 3 years ago

my code is :

import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:http/http.dart' as http; import 'package:pokemon/pokemon_list_modal.dart'; import 'dart:convert';

void main() => runApp(MaterialApp( title: "Pokemon", theme: ThemeData(primarySwatch: Colors.teal), debugShowCheckedModeBanner: false, home: HomePage(), ));

//MARK:- This is our first Page. class HomePage extends StatefulWidget { // This widget is the root of your application. @override _HomePageState createState() => _HomePageState(); }

class _HomePageState extends State { var url = "https://raw.githubusercontent.com/Biuni/PokemonGO-Pokedex/master/pokedex.json";

PokemonList pokemonList;

@override void initState() { super.initState(); getPokemonList(); // fetchData(); }

getPokemonList() async { var res = await http.get(url); var decodedValue = jsonDecode(res.body); pokemonList = PokemonList.fromJson(decodedValue);

print(pokemonList.pokemon[0].name);

}

Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text("Pokemons"), centerTitle: true, ), body: pokemonList == null ? Center( child: CircularProgressIndicator(), ) : GridView.count( crossAxisCount: 2, // children: [], children: pokemonList.pokemon.map((Pokemon poke) => Card()).toList(), ), drawer: Drawer(), floatingActionButton: FloatingActionButton( onPressed: () {}, child: Icon(Icons.refresh), ), ); } }