Professional Documents
Culture Documents
Date: 18-05-2021
Time: 10:00 AM - 1:00 PM
Objectives
The objective of this lab is helping students to familiarize themselves that how to calls API’s in
Flutter.
Description
API stands for Application Programming Interface. It can be defined as a set of protocols,
procedures, and tools that allow interaction between two applications.
In a nutshell, an API call is a process that takes place when you send a request after setting up
your API with the correct endpoints. Your information is transferred, processed, and feedback is
returned back.
Let’s consider this scenario, in which you(client) are in a restaurant. You sit on your table and
decide to eat A. You need to call the waiter(API call) and place your order(request) for A. The
waiter gets to the kitchen(server) to prepare A and serves(response) A. Now you get your
delicious food A(JSON or XML data) and everyone is happy. In this case, your interface
between you and the kitchen(Server) is your waiter(API). It’s his responsibility to carry
the request from you to the kitchen(Server), make sure it’s getting done, and you know once it
is ready he gets back to you as a response(JSON or XML data).
Tools/Software Requirement
Helping Material:
- https://flutter.dev/docs/cookbook/networking/fetch-data
- https://flutter.dev/docs/cookbook/networking/send-data
- Flutter official Documentation
- Stack overflow
dependencies:
http: <latest_version>
Import the http package.
2. Make a network request using the http package and call the below API .
https://jsonplaceholder.typicode.com/todos
a). Install the Postman or add Restlet Client chrome extension to test the above API.
b). Check the response of above API by using postman or Restlet Client.
a). get id and title from json response and display it like (shown below).
Solution
Task Code:
http: 0.12.2
flutter:
sdk: flutter
2) class Data {
return Data(
userId: json['userId'],
id: json['id'],
title: json['title'],
);
final response =
if (response.statusCode == 200) {
} else {
FutureBuilder <List<Data>>(
future: futureData,
if (snapshot.hasData) {
return
ListView.builder(
itemCount: data.length,
return Container(
height: 75,
color: Colors.white,
),);
);
} else if (snapshot.hasError) {
return Text("${snapshot.error}");
import 'dart:async';
import 'dart:convert';
import 'package:flutter/material.dart';
final response =
await http.get('https://jsonplaceholder.typicode.com/albums');
if (response.statusCode == 200) {
} else {
return Data(
userId: json['userId'],
id: json['id'],
title: json['title'],
);
@override
@override
void initState() {
super.initState();
futureData = fetchData();
@override
return MaterialApp(
home: Scaffold(
appBar: AppBar(
),
body: Center(
if (snapshot.hasData) {
return
ListView.builder(
itemCount: data.length,
return Container(
height: 75,
color: Colors.white,
),);
);
} else if (snapshot.hasError) {
return Text("${snapshot.error}");
return CircularProgressIndicator();
},
),
),
);
Compile a single word document by filling in the solution part and submit this Word file on
LMS. This lab grading policy is as follows: The lab is graded between 0 to 10 marks. The
submitted solution can get a maximum of 5 marks. At the end of each lab or in the next lab, there
will be a viva/quiz related to the tasks. You must show the implementation of the tasks in the
designing tool, along with your complete Word document to get your work graded. You must
also submit this Word document on the LMS. In case of any problems with submissions on
LMS, submit your Lab assignments by emailing it to Mis Shakeela: shakeela.bibi@seecs.edu.pk.