0
0
Fluttermobile~5 mins

http package in Flutter - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of the http package in Flutter?
The http package allows Flutter apps to send and receive data over the internet using HTTP requests like GET and POST.
Click to reveal answer
beginner
How do you add the http package to a Flutter project?
Add http: ^0.13.6 (or latest version) under dependencies in pubspec.yaml and run flutter pub get.
Click to reveal answer
beginner
What Flutter code snippet sends a simple GET request using the http package?
import 'package:http/http.dart' as http;

void fetchData() async {
  var response = await http.get(Uri.parse('https://example.com'));
  if (response.statusCode == 200) {
    print(response.body);
  }
}
Click to reveal answer
beginner
What does the Uri.parse() method do in the context of the http package?
It converts a string URL into a Uri object, which is required by the http methods to specify the web address.
Click to reveal answer
intermediate
How can you send data with a POST request using the http package?
Use http.post() with the body parameter containing data as a map or encoded string, for example: await http.post(Uri.parse('https://example.com'), body: {'key': 'value'});
Click to reveal answer
Which method from the http package is used to fetch data from a web server?
Ahttp.post()
Bhttp.get()
Chttp.put()
Dhttp.delete()
What type of object must you pass to http.get() as the URL parameter?
AUri
BString
Cint
DList
How do you check if an HTTP request was successful in Flutter using the http package?
ACheck if <code>response.statusCode == 404</code>
BCheck if <code>response.body != null</code>
CCheck if <code>response.headers</code> is empty
DCheck if <code>response.statusCode == 200</code>
Which import statement is correct to use the http package with an alias?
Aimport 'package:flutter/http.dart';
Bimport 'http.dart';
Cimport 'package:http/http.dart' as http;
Dimport 'http';
What is the main difference between http.get() and http.post()?
A<code>get()</code> retrieves data; <code>post()</code> sends data to the server
B<code>get()</code> sends data; <code>post()</code> retrieves data
CBoth do the same thing
D<code>post()</code> deletes data; <code>get()</code> updates data
Explain how to perform a GET request using the Flutter http package and handle the response.
Think about the steps from importing the package to printing the data.
You got /5 concepts.
    Describe how to send data to a server using a POST request with the Flutter http package.
    Focus on how you include data in the request.
    You got /5 concepts.