Complete the code to import the http package in Flutter.
import 'package:[1]/http.dart' as http;
The http package is imported using package:http/http.dart. This allows you to use http methods like get and post.
Complete the code to send a GET request to fetch data from a URL.
var response = await http.[1](Uri.parse('https://example.com/data'));
The get method sends a GET request to the specified URL to retrieve data.
Fix the error in the code to correctly parse the response body as a string.
if (response.statusCode == 200) { var data = response.[1]; }
The body property contains the response content as a string, which is what you want to parse.
Fill both blanks to send a POST request with JSON data and set the correct header.
var response = await http.post( Uri.parse('https://example.com/api'), headers: {'Content-Type': '[1]'}, body: [2] );
When sending JSON data, the header must be 'application/json'. The body must be a JSON string, so use double quotes inside the string.
Fill all three blanks to decode JSON response and access a field named 'title'.
import 'dart:convert'; var jsonResponse = json.[1](response.[2]); var title = jsonResponse['[3]'];
Use json.decode to convert the JSON string from response.body into a Dart map. Then access the 'title' field from the map.