HackIndia Logo
HackathonsNewsSkillsGrowth
HackIndia LogoContact: +91 9910125804

General

  • Companies
  • Colleges
  • Board of Advisors
  • Brand Ambassadors
  • FAQ
  • Contact
  • Report a Bug

Hackathons

  • Upcoming Hackathons
  • Judges
  • Mentors
  • Partners
  • Participating Colleges
  • Testimonials

Resources

  • About Us
  • Branding
  • Latest News
  • Growth
  • Skills
  • Builders
  • Ecosystem
  • Forum
  • Ideas
  • Prompt Optimizer
  • Games

© 2026 HackIndia. All rights reserved.

Privacy PolicyTerms of ServiceCode of ConductSitemap

Build 2.139 · 05 Nov 2026, 10:27 UTC

    HackIndia
    HackathonsNewsInternshipsSkillsGrowthPro Perks
    FlutterWorking towardsFlutter
    0%

    0 of 9 steps done · +100 XP · +50 SHARP when it is yours

    1. 1Create your first Flutter screen5 min · +10 XP · +5 SHARP
    2. 2Use stateless and stateful widgets4 min · +10 XP · +5 SHARP
    3. 3Move between app screens4 min · +10 XP · +5 SHARP
    4. 4Fetch API data safely5 min · +10 XP · +5 SHARP
    5. 5Store data on the device4 min · +10 XP · +5 SHARP
    6. 6Prepare a phone demo build4 min · +10 XP · +5 SHARP
    7. 7Submit your public repo4 min · +10 XP · +5 SHARP
    8. The check10 questions, 7 to pass · +10 SHARP
    9. Hand in the taskA project that uses the skill
    10. Skill and certificate+100 XP · +50 SHARP
    Lesson 4 of 7 5 min

    Flutter

    Fetch API data safely

    • +10 XP for this lesson
    • +100 XP when the skill is proved
    • Nobody here has proved it yet
    In 30 seconds
    • Fetch JSON from an API using the http package.
    • Show loading, success, and error states with FutureBuilder.
    Avoid repeated API calls by not fetching inside build().
    Key point

    One safe pattern

    Create the request once, store it in a Future, and let FutureBuilder draw the UI states.

    Do not call the API directly inside build(). Flutter can rebuild often, and that can repeat the same request.

    Your to-do

    Add networking

    Do each one yourself, then tap it to tick it off. The ticks are only a checklist for you: they are not marked or scored.

    0 of 5 done

    flutter pub add http
    Example

    Android permission

    Your app needs permission before it can fetch data on Android. Put this inside the manifest, above the application tag.

    If an older tutorial says the default template already has this, do not rely on it.

    <uses-permission android:name="android.permission.INTERNET" />
    Example

    Fetch one item

    This example uses JSONPlaceholder because it is public and simple. Replace it later with an API related to your demo app, like events, jobs, products, or tasks.

    Keep parsing strict. If the response is not OK, throw an error so the UI can show a useful state.

    import 'dart:convert';
    import 'package:flutter/material.dart';
    import 'package:http/http.dart' as http;
    
    class Album {
      final int id;
      final String title;
    
      Album({required this.id, required this.title});
    
      factory Album.fromJson(Map<String, dynamic> json) {
        return Album(
          id: json['id'] as int,
          title: json['title'] as String,
        );
      }
    }
    
    Future<Album> fetchAlbum() async {
      final uri = Uri.parse('https://jsonplaceholder.typicode.com/albums/1');
      final response = await http.get(uri);
    
      if (response.statusCode == 200) {
        return Album.fromJson(jsonDecode(response.body) as Map<String, dynamic>);
      }
    
      throw Exception('Failed to load album');
    }
    Example

    Show API states

    Make the Future in initState(). Then build only reads that Future.

    This gives your recruiter a clean demo: spinner while loading, text when data arrives, and a visible error if something breaks.

    class ApiDemoScreen extends StatefulWidget {
      const ApiDemoScreen({super.key});
    
      @override
      State<ApiDemoScreen> createState() => _ApiDemoScreenState();
    }
    
    class _ApiDemoScreenState extends State<ApiDemoScreen> {
      late Future<Album> albumFuture;
    
      @override
      void initState() {
        super.initState();
        albumFuture = fetchAlbum();
      }
    
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          appBar: AppBar(title: const Text('API Demo')),
          body: Center(
            child: FutureBuilder<Album>(
              future: albumFuture,
              builder: (context, snapshot) {
                if (snapshot.connectionState == ConnectionState.waiting) {
                  return const CircularProgressIndicator();
                }
    
                if (snapshot.hasError) {
                  return Text('Error: ${snapshot.error}');
                }
    
                if (snapshot.hasData) {
                  return Padding(
                    padding: const EdgeInsets.all(16),
                    child: Text(snapshot.data!.title),
                  );
                }
    
                return const Text('No data found');
              },
            ),
          ),
        );
      }
    }
    Common mistake

    Common mistake

    Do not write future: fetchAlbum() inside FutureBuilder. It looks short, but it can run again when the widget rebuilds.

    Also avoid hiding errors with empty screens. During hackathon demos, a clear error message is better than a blank app.

    Tip

    Use AI carefully

    You can ask ChatGPT or Gemini to create a model class from sample JSON. Paste only public sample data, not private API keys.

    Check the AI output for three things: correct field types, null values from the API, and whether it throws a clear error when the request fails.

    Your to-do

    Do this now

    Do each one yourself, then tap it to tick it off. The ticks are only a checklist for you: they are not marked or scored.

    0 of 5 done

    Sources

    Checked against the current documentation on 21 September 2026.

    • Fetch data from the internet · docs.flutter.dev
    • Build and release an Android app · docs.flutter.dev

    Quick check

    0 of 2 right
    1.Your API screen rebuilds when the phone rotates. Where should you create the Future to avoid repeating the request?
    2.Your Android app shows an error before any API data loads. What setup step should you check first?

    Answer the quick check to finish this lesson.

    ← Lesson 3Skip to lesson 5 →
    Flutter
    Working towards
    Flutter +100 XP

    0 of 7 lessons done · proved by a project that uses the skill

    See the track