πΌNetworking
1. Adding the http Package π¦
http Package π¦dependencies:
flutter:
sdk: flutter
http: ^1.1.02. Sending a GET Request π€
import 'package:http/http.dart' as http;
Future<void> fetchPost() async {
final response = await http.get(Uri.parse('https://jsonplaceholder.typicode.com/posts/1'));
if (response.statusCode == 200) {
// If the server returns an OK response, parse the JSON
print('Response data: ${response.body}');
} else {
// If the server did not return a 200 OK response, throw an exception.
throw Exception('Failed to load post');
}
}3. Sending a POST Request π₯
4. Error Handling π
Complete Example Code π

Assignments π
Last updated