• Stars
    star
    498
  • Rank 88,494 (Top 2 %)
  • Language
    Dart
  • Created over 6 years ago
  • Updated over 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Experimenting with 6 examples of different types of simple and complex JSON structures in Flutter

Parsing complex JSON in Flutter

Gives a detailed explanation of working with simple and complex JSON structures using dart:convert library in Flutter along with a sample project with 6+ examples to experiment with.

Tutorial

Read the Medium article here

Types of JSON structures

  • Simple map
  • Simple structure with arrays
  • Simple nested structures
  • Nested structure with Lists
  • List of maps
  • Complex nested structures
  • Simple structure with Nested Maps [parsed using json_serializable library]
  • Demo for Network Calls with examples for GET, POST methods along with FutureBuilder and .then()

How to work with Network Calls?

Not covered in the article

Let's take this API as an example.

Take a look at post_model.dart for the model class and utility methods. I produced it using this converter tool

GET getAllPosts

//services.dart
Future<List<Post>> getAllPosts() async {
  final response = await http.get(url);
  return allPostsFromJson(response.body);
}
// As a part of your UI widget, e.g body of Scaffold widget
FutureBuilder<List<Post>>(
            future: getAllPosts(),
            builder: (context, snapshot) {
              if(snapshot.hasData)
                return Text('Title from Post JSON : ${snapshot.data[0].title}');
              else
                return CircularProgressIndicator();
            }
        )

GET getPost (to get a particular POST by id)

//services.dart
Future<Post> getPost() async{
  final response = await http.get('$url/1'); // the number is the id of the item being accessed
  return postFromJson(response.body);
}
// As a part of your UI widget, e.g body of Scaffold widget
FutureBuilder<Post>(
            future: getPost(),
            builder: (context, snapshot) {
              if(snapshot.hasData)
                return Text('Title from Post JSON : ${snapshot.data.title}');
              else
                return CircularProgressIndicator();
            }
        )

POST createPost

//services.dart
Future<http.Response> createPost(Post post) async{
  final response = await http.post('$url',
      headers: {
        HttpHeaders.contentTypeHeader: 'application/json'
      },
      body: postToJson(post)
  );

  return response;
}
  //call this function when you want to create a new post
 callAPI(){
    Post post = Post(
      body: 'Testing body body body',
      title: 'Flutter jam6'
    ); // creating a new Post object to send it to API
    
    createPost(post).then((response){
        if(response.statusCode > 200)
          print(response.body);
        else
          print(response.statusCode);
    }).catchError((error){
      print('error : $error');
    });
    
  }

More Repositories

1

FlutterBasicWidgets

ABC of Flutter widgets. Intended for super beginners at Flutter. Play with 35+ examples in DartPad directly and get familiar with various basic widgets in Flutter
Dart
864
star
2

AwesomeFlutterPlaylist

A collection of the best tutorials on Flutter development from the community
353
star
3

Summer-Internship-Prep

30
star
4

ToDoList-ChromeExtension

A simple Chrome extension that replaces your new tab page with the to-do list of the day along with your to-learn checklist
JavaScript
29
star
5

WeatherHome

Static weather app build in Flutter to get the hang of basic widgets, specially Rows and Columns.
Dart
25
star
6

FlightBookingFlutter

Recreating a Flight Booking application for Flutter Study Jam BBSR DAY 2
Dart
23
star
7

LayoutsFlutter

Examples of layouts built in Flutter
Dart
22
star
8

NavigatorsDemo-Flutter

Overview of Navigator methods in Flutter
Dart
16
star
9

Hackathons-Around-The-World

Know which hackathons are happening around you, around the world! Contributions are welcome!
16
star
10

VisualSearch-TensorFlow-Android

Visual search application to capture real-time image of a product and recommend similar items from database/API.
Java
16
star
11

Mini-Flutters

Beginner level mini Flutter projects
Dart
15
star
12

CarouselOverlappingCards-Flutter

Overlapping cards vertical scrolling with carousel effect
Dart
14
star
13

rainbowflag

Creating a rainbow flag animation in Flutter to celebrate victory for LGBTQ community
Dart
14
star
14

FlutterAudioExperiments

Experimenting with Audio recording, playing and voice to text speech.
Dart
14
star
15

FlutterUIChallenges

Recreating famous UI in Flutter
Dart
13
star
16

WidgetTestingForDummies

Complimentary repository for the talk "Widget Testing For Dummies", focuses on Widget Tests.
Dart
13
star
17

HearMeNow-DepressionChatbot-Dialogflow

Have a story to share? Feeling depressed? Want to give up? Feeling suicidal? HearMeNow is here to hear you out.
Java
11
star
18

Mentorships-for-Women-in-Technology

A curated list of the technical mentorships, internships specially organized for women.
9
star
19

flutter_choreography

Dart
9
star
20

GithubSearchFlutter

Example using Githb Search APIs to demo async loading with async_loader plugin
Dart
9
star
21

JingleBellsFlutter

Play #JingleBells with Flutter // Holiday themed #FlutterCounterChallenge2020
Dart
8
star
22

flutter_events

Dart
8
star
23

GithubTrendingRepos-Flutter

Returns the list of Trending repositories in Github filtered by Language and Duration, built for Day 3 of Flutter Study Jam
Dart
8
star
24

dynamic_maps

Dart
6
star
25

TextRecognizer-FirebaseMLKit

Java
6
star
26

NoLibrary-Page-Indicators

A little hack to make circular/dot indicators for your view pagers in your Android projects without the use of third party libraries
Java
5
star
27

poojab26.github.io

CSS
5
star
28

profile_app

Profile App built for the KIIT Ecell Community Learning Flutter Workshp
Dart
4
star
29

FlutterHost

Flutter Host Android app with setup to add Flutter code.
Java
4
star
30

FlutterAnimationPlayground

Dart
3
star
31

bird_instagram

Dart
3
star
32

Android-Interview-Prep

A collection of questions, answers, resources, tips for Android technical interviews.
3
star
33

flutter_module

Dart
3
star
34

bounce_workshop

Dart
3
star
35

BakingApp-Project3UdacityNanodegree

Project 3 of Android Developer Nanodegree
Java
2
star
36

StateManagementDemos-Flutter

Dart
1
star
37

AwesomeAPIs

An Awesome list of curated useful APIs for Hackathons, Personal Projects, etc.
1
star
38

BatteryIndicatorWidget_Android

For internship assignment
Java
1
star
39

NearbyRestaurants-ZomatoAPI-Android

Java
1
star
40

Algorithms

C
1
star
41

KitchenOfCoding-InteractivePythonTutorialPlatform

An online interactive platform, that aims to teach programming concepts and languages to home-makers and housewives, in the form of recipes.
JavaScript
1
star
42

ContentProviderExample

A quick and easy example of data persistence on Android
Java
1
star
43

XYZReader-UdacityMaterialDesignProject

Project 4 of Android Developer Nanodegree Udacity
Java
1
star
44

BlockchainDemo-NodeJS

Built for Hack InOut Hackathon 2017
JavaScript
1
star
45

TrackCollegeAttendance-Android

Java
1
star
46

GoogleMaps-UdacityCourse

Collection of the lessons taught in Google Maps Udacity Course along with screenshots
Java
1
star
47

PopularMovies-Project1UdacityNanodegree

Project 1 for Udacity Android Developer Nanodegree
Java
1
star
48

ShoppingAppFirebase

Java
1
star
49

OpenSourceWeekend

Day 2 activity of Open Source Weekend organised by xxCode team for women developers
C
1
star
50

PopularMovies2-Project2UdacityNanodegree

Project 2 of Android Development Udacity Nanodegree
Java
1
star
51

RecyclerView-Retrofit-StarterCode-Android

Java
1
star