flutter-handling-http-and-json
HTTP requests and JSON serialization for Flutter REST API integration and data parsing.
- Covers three HTTP methods (GET, POST, PUT, DELETE) with proper status code validation, HTTPS enforcement, and safe URI construction using
Uri.https(). - Offers two serialization strategies: manual
fromJson/toJsonfor simple models, and code generation withjson_serializablefor complex nested structures. - Includes background parsing with
compute()to prevent UI jank when processing large JSON payloads (1000+ items). - Provides platform-specific configuration guidance for Android and iOS network security policies.
Handling HTTP and JSON
Contents
- Core Guidelines
- Workflow: Executing HTTP Operations
- Workflow: Implementing JSON Serialization
- Workflow: Parsing Large JSON in the Background
- Examples
Core Guidelines
- Enforce HTTPS: iOS and Android disable cleartext (HTTP) connections by default. Always use HTTPS endpoints. If HTTP is strictly required for debugging, configure
network_security_config.xml(Android) andNSAppTransportSecurity(iOS). - Construct URIs Safely: Always use
Uri.https(authority, unencodedPath, [queryParameters])to safely build URLs. This handles encoding and formatting reliably, preventing string concatenation errors. - Handle Status Codes: Always validate the
http.Response.statusCode. Treat200(OK) and201(Created) as success. Throw explicit exceptions for other codes (do not returnnull). - Prevent UI Jank: Move expensive JSON parsing operations (taking >16ms) to a background isolate using the
compute()function. - Structured AI Output: When integrating LLMs, enforce reliable JSON output by specifying a strict JSON schema in the system prompt and setting the response MIME type to
application/json.
Workflow: Executing HTTP Operations
Use this workflow to implement network requests using the http package.
More from flutter/skills
flutter-building-layouts
Builds Flutter layouts using the constraint system and layout widgets. Use when creating or refining the UI structure of a Flutter application.
10.6Kflutter-architecting-apps
Architects a Flutter application using the recommended layered approach (UI, Logic, Data). Use when structuring a new project or refactoring for scalability.
10.4Kflutter-animating-apps
Implements animated effects, transitions, and motion in a Flutter app. Use when adding visual feedback, shared element transitions, or physics-based animations.
9.6Kflutter-managing-state
Manages application and ephemeral state in a Flutter app. Use when sharing data between widgets or handling complex UI state transitions.
9.6Kflutter-theming-apps
Customizes the visual appearance of a Flutter app using the theming system. Use when defining global styles, colors, or typography for an application.
9.5Kflutter-implementing-navigation-and-routing
Handles routing, navigation, and deep linking in a Flutter application. Use when moving between screens or setting up URL-based navigation.
9.3K