Complete Code

Now, let’s dive into the complete code for Pokémon app. When Flutter app is created, main.dart is already present in its folder. In main.dart file, write the following code –

Dart




import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
import 'dart:convert';
import 'dart:core';
  
void main() {
  runApp(MyApp());
}
  
class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: MyHomePage(),
    );
  }
}
  
class MyHomePage extends StatefulWidget {
  @override
  _MyHomePageState createState() => _MyHomePageState();
}
  
class _MyHomePageState extends State<MyHomePage> {
  Map pokeData = {};
  
  List pokeList = [];
  
  Future<void> getData() async {
    http.Response pokeResponse;
    String urlString =
        "https://raw.githubusercontent.com/Biuni/PokemonGO-Pokedex/master/pokedex.json";
    Uri uri = Uri.parse(urlString);
  
    pokeResponse = await http.get(uri);
  
    if (pokeResponse.statusCode == 200) {
      pokeData = json.decode(pokeResponse.body);
      pokeList = pokeData['pokemon'];
    } else {
      throw Exception('Failed to load data from the API');
    }
  }
  
  void initState() {
    getData();
    super.initState();
  }
  
  Widget build(BuildContext context) {
    return Scaffold(
        backgroundColor: Colors.white,
        appBar: AppBar(
          title: Text("PokeDex"),
          backgroundColor: Colors.green,
        ),
        body: pokeList == null
            ? Center(child: Text("Wait"))
            : ListView.builder(
                itemCount: pokeList == null ? 0 : pokeList.length,
                itemBuilder: (context, index) {
                  return Container(
                    child: Column(
                      children: <Widget>[
                        Padding(
                          padding: const EdgeInsets.all(10.0),
                          child: Container(
                            height: 300,
                            width: 300,
                            decoration: BoxDecoration(
                                color: Colors.green,
                                borderRadius: BorderRadius.circular(20)),
                            child: Column(
                              children: [
                                Padding(
                                  padding: const EdgeInsets.all(8.0),
                                  child: Text(
                                    pokeList[index]['name'],
                                    style: TextStyle(
                                        fontSize: 20,
                                        fontWeight: FontWeight.w600,
                                        color: Colors.white),
                                  ),
                                ),
                                Image.network(
                                  pokeList[index]['img'],
                                  width: 300,
                                  height: 200,
                                ),
                                Row(
                                  mainAxisAlignment: MainAxisAlignment.center,
                                  children: [
                                    Text(
                                      "Candy: ",
                                      style: TextStyle(
                                          fontSize: 15,
                                          fontWeight: FontWeight.w500,
                                          color: Colors.white),
                                    ),
                                    Text(pokeList[index]['candy'],
                                        style: TextStyle(
                                            fontSize: 15,
                                            color: Colors.white,
                                            fontWeight: FontWeight.w500)),
                                  ],
                                ),
                                SizedBox(
                                  height: 10,
                                ),
                              ],
                            ),
                          ),
                        )
                      ],
                    ),
                  );
                },
              ));
  }
}


Output:

Flutter – Creating a Simple Pokémon App

Embark on an exciting journey into the vibrant world of Pokémon with an innovative mobile app, that we will be building in this article – ‘PokeDex.’ Powered by the versatile Flutter framework and integrated with the extensive Pokemon API, this app redefines the Pokémon experience. Flutter is a cutting-edge open-source UI framework developed by Google, that empowers us to craft seamless, visually appealing applications across mobile, web, and desktop platforms, all from a unified codebase.

Similar Reads

Features of Application

Comprehensive Pokémon Database: Explore an extensive collection of Pokémon characters, each meticulously detailed with their names, captivating images, and valuable candy information. Intuitive User Interface: Dive into an intuitive and user-friendly interface designed to enhance exploration of the Pokémon universe. Effortlessly navigate through the app and discover a world of Pokémon at your fingertips. Real-time Data Fetching: Stay up-to-date with the latest Pokémon information thanks to real-time data fetching capabilities. Experience the thrill of discovering new Pokémon and their unique traits as soon as they are available. Seamless Cross-Platform Compatibility: It’s a single codebase application that serves on mobile devices, desktops, or web browsers, and ensures a consistent and immersive experience....

Preview

...

Approach

We will create a StatefulWidget to manage state, specifically the pokeData and pokeList variables. In next step we would complete the getData method to fetch Pokémon data from the API. Once the data is successfully fetched and stored, the UI in the body of the Scaffold widget would be updated to display the Pokémon information, such as names, images, and other details, using ListView widget....

Step By Step Implementation

Step 1: Create a New Project in Visual Studio Code or Android Studio....

Complete Code

...

Conclusion

...