flutter-use-http-package
flutter/agent-plugins
Execute GET, POST, PUT, and DELETE requests in Flutter using the http package for REST API integration.
What is flutter-use-http-package?
This skill enables Flutter developers to make HTTP requests to REST APIs using the `http` package. Use it when you need to fetch data from or send data to a backend service, with proper error handling, JSON deserialization, and UI integration via FutureBuilder.
- Execute GET, POST, PUT, and DELETE HTTP requests with custom headers and request bodies
- Parse JSON responses into strongly typed Dart models using factory constructors
- Offload expensive JSON parsing to background isolates to prevent UI frame drops
- Validate HTTP status codes and throw explicit exceptions on failure
- Integrate network operations into Flutter UI using FutureBuilder with loading and error states
How to install flutter-use-http-package
npx skills add https://github.com/flutter/agent-plugins --skill flutter-use-http-package- Flutter project set up and running
- Android: Internet permission added to AndroidManifest.xml
- macOS: Network client entitlement added to entitlements files
How to use flutter-use-http-package
- 1.Run `flutter pub add http` to add the http package dependency
- 2.Import the package in your Dart files with `import 'package:http/http.dart' as http`
- 3.Define a strongly typed Dart model class with a `fromJson` factory constructor
- 4.Implement a network request method that returns `Future<YourModel>`, parsing the response body and validating the status code
- 5.Use `compute()` from `package:flutter/foundation.dart` to parse JSON in a background isolate for better performance
- 6.Integrate the Future into your UI using `FutureBuilder`, handling `snapshot.hasData`, `snapshot.hasError`, and loading states
- 7.Test the implementation by running the app and triggering network requests while monitoring the console for errors
Use cases
- Fetching a list of items from a REST API and displaying them in a ListView
- Submitting form data via POST request to create a new resource on the backend
- Updating an existing resource with PUT request and handling the response
- Deleting a resource via DELETE request and refreshing the UI
- Authenticating with a backend by including Bearer tokens in request headers
- Flutter app developers building client-server applications
- Mobile engineers integrating third-party REST APIs
- Teams needing to handle network requests with proper error handling and UI feedback
flutter-use-http-package FAQ
Use `compute()` when parsing large JSON responses (typically >100KB) to prevent UI jank. For small responses, synchronous parsing is acceptable.
Treat 200 OK (GET/PUT/DELETE) and 201 CREATED (POST) as success. All other codes should trigger an exception.
Returning null prevents FutureBuilder from triggering its error state, causing infinite loading indicators. Always throw an explicit Exception instead.
Use the `headers` parameter map with `HttpHeaders.authorizationHeader: 'Bearer your_token_here'` to inject auth tokens into requests.
No, the parsing function must be a top-level function or static method, not a closure or instance method, as they cannot be serialized across isolates.
Full instructions (SKILL.md)
Source of truth, from flutter/agent-plugins.
name: flutter-use-http-package
description: Use the http package to execute GET, POST, PUT, or DELETE requests. Use when you need to fetch from or send data to a REST API.
metadata:
model: models/gemini-3.1-pro-preview
last_modified: Tue, 21 Apr 2026 21:36:42 GMT
Implementing Flutter Networking
Contents
- Configuration & Permissions
- Request Execution & Response Handling
- Background Parsing
- Workflow: Executing Network Operations
- Examples
Configuration & Permissions
Configure the environment and platform-specific permissions required for network access.
- Add the
httppackage dependency via the terminal:flutter pub add http - Import the package in your Dart files:
import 'package:http/http.dart' as http; - Configure Android permissions by adding the Internet permission to
android/app/src/main/AndroidManifest.xml:<uses-permission android:name="android.permission.INTERNET" /> - Configure macOS entitlements by adding the network client key to both
macos/Runner/DebugProfile.entitlementsandmacos/Runner/Release.entitlements:<key>com.apple.security.network.client</key> <true/>
Request Execution & Response Handling
Execute HTTP operations and map responses to strongly typed Dart objects.
- URIs: Always parse URL strings using
Uri.parse('your_url'). - Headers: Inject authorization and content-type headers via the
headersparameter map. UseHttpHeaders.authorizationHeaderfor auth tokens. - Payloads: For POST and PUT requests, encode the body using
jsonEncode()fromdart:convert. - Status Validation: Evaluate
response.statusCode. Treat200 OK(GET/PUT/DELETE) and201 CREATED(POST) as success. - Error Handling: Throw explicit exceptions for non-success status codes. Never return
nullon failure, as this preventsFutureBuilderfrom triggering its error state and causes infinite loading indicators. - Deserialization: Parse the raw string using
jsonDecode(response.body)and map it to a custom Dart object using a factory constructor (e.g.,fromJson).
Background Parsing
Offload expensive JSON parsing to a separate Isolate to prevent UI jank (frame drops).
- Import
package:flutter/foundation.dart. - Use the
compute()function to run the parsing logic in a background isolate. - Ensure the parsing function passed to
compute()is a top-level function or a static method, as closures or instance methods cannot be passed across isolates.
Workflow: Executing Network Operations
Use the following checklist to implement and validate network operations.
Task Progress:
- 1. Define the strongly typed Dart model with a
fromJsonfactory constructor. - 2. Implement the network request method returning a
Future<Model>. - 3. Apply conditional logic based on the operation type:
- If fetching data (GET): Append query parameters to the URI.
- If mutating data (POST/PUT): Set
'Content-Type': 'application/json; charset=UTF-8'and attach thejsonEncodebody. - If deleting data (DELETE): Return an empty model instance on success (
200 OK).
- 4. Validate the
statusCodeand throw anExceptionon failure. - 5. Integrate the
Futureinto the UI usingFutureBuilder. - 6. Handle
snapshot.hasData,snapshot.hasError, and default to aCircularProgressIndicator. - 7. Feedback Loop: Run the app -> trigger the network request -> review console for unhandled exceptions -> fix parsing or permission errors.
Examples
High-Fidelity Implementation: Fetching and Parsing in the Background
import 'dart:async';
import 'dart:convert';
import 'dart:io';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
// 1. Top-level parsing function for Isolate
List<Photo> parsePhotos(String responseBody) {
final parsed = (jsonDecode(responseBody) as List<Object?>)
.cast<Map<String, Object?>>();
return parsed.map<Photo>(Photo.fromJson).toList();
}
// 2. Network execution with background parsing
Future<List<Photo>> fetchPhotos() async {
final response = await http.get(
Uri.parse('https://jsonplaceholder.typicode.com/photos'),
headers: {
HttpHeaders.authorizationHeader: 'Bearer your_token_here',
HttpHeaders.acceptHeader: 'application/json',
},
);
if (response.statusCode == 200) {
// Offload heavy parsing to a background isolate
return compute(parsePhotos, response.body);
} else {
throw Exception('Failed to load photos. Status: ${response.statusCode}');
}
}
// 3. Strongly typed model
class Photo {
final int id;
final String title;
final String thumbnailUrl;
const Photo({
required this.id,
required this.title,
required this.thumbnailUrl,
});
factory Photo.fromJson(Map<String, dynamic> json) {
return Photo(
id: json['id'] as int,
title: json['title'] as String,
thumbnailUrl: json['thumbnailUrl'] as String,
);
}
}
// 4. UI Integration
class PhotoGallery extends StatefulWidget {
const PhotoGallery({super.key});
@override
State<PhotoGallery> createState() => _PhotoGalleryState();
}
class _PhotoGalleryState extends State<PhotoGallery> {
late Future<List<Photo>> _futurePhotos;
@override
void initState() {
super.initState();
// Initialize Future once to prevent re-fetching on rebuilds
_futurePhotos = fetchPhotos();
}
@override
Widget build(BuildContext context) {
return FutureBuilder<List<Photo>>(
future: _futurePhotos,
builder: (context, snapshot) {
if (snapshot.hasData) {
final photos = snapshot.data!;
return ListView.builder(
itemCount: photos.length,
itemBuilder: (context, index) => ListTile(
leading: Image.network(photos[index].thumbnailUrl),
title: Text(photos[index].title),
),
);
} else if (snapshot.hasError) {
return Center(child: Text('Error: ${snapshot.error}'));
}
// Default loading state
return const Center(child: CircularProgressIndicator());
},
);
}
}
Related skills
More from flutter/agent-plugins and the wider catalog.

flutter-working-with-databases
Agent skill from flutter/agent-plugins.

dart-setup-ffi-assets
Compile and package C/C++ code into Dart Native Assets with automated build hooks and tree-shaking optimization.

dart-use-ffigen
Automatically generate FFI bindings for C/Objective-C/Swift libraries instead of writing them manually.

dart-use-path-package
Cross-platform file path manipulation for Dart—join, split, and normalize paths safely on Windows and POSIX.

flutter-accessibility
Configure Flutter apps for accessibility with screen readers, keyboard navigation, and adaptive layouts.

flutter-accessibility-audit
Automatically scan Flutter apps for accessibility issues and inject missing Semantics widgets and labels.