Junior — Middle
What tools or libraries do you use or know for working with HTTP requests?
sobes.tech AI
Answer from AI
In Flutter, the http package is often used for working with HTTP requests, providing a simple API for sending GET, POST, and other requests. The dio library is also popular, offering more features such as interceptors, request cancellation, file uploads, etc.
Example of using the http package:
import 'package:http/http.dart' as http;
void fetchData() async {
final response = await http.get(Uri.parse('https://jsonplaceholder.typicode.com/posts/1'));
if (response.statusCode == 200) {
print('Response body: ${response.body}');
} else {
print('Request failed with status: ${response.statusCode}.');
}
}
For more complex cases, such as managing request states, you can use dio or integrate with flutter_bloc, provider, etc.