Sub topic 10
Inspecting HTTP Traffic with the Network View
What the Network View shows
Assume you can run a Flutter app on an emulator or device, use Future and async code, and understand the widget tree. The Network view helps you connect an app symptom to an HTTP request. It shows requests made by Dart networking code, including requests made through package:http and dart:io.
Use it to answer questions such as:
- Did the request start when the user tapped the button?
- Which URL and HTTP method did the app use?
- How long did the request take?
- What status code did the server return?
- Did the app send the expected headers or body?
- Did the server return an error or unexpected data?
The Network view is different from the browser's Network panel. It observes traffic from the Dart application. For Flutter web, use the browser's developer tools for browser-managed network traffic.
Start recording and make a request
Start your app, open DevTools, and select Network. Make sure network recording is enabled if the view provides a recording control. Trigger the app action that loads data. A request row should appear after the request starts or completes.
This example uses package:http. Add the package to a Flutter project before running it:
flutter pub add httpThe function sends a GET request and checks both the HTTP status and the decoded response shape:
import 'dart:convert';
import 'package:http/http.dart' as http;
Future<List<dynamic>> loadProducts() async {
final uri = Uri.https('fakestoreapi.com', '/products');
final response = await http.get(
uri,
headers: const {'Accept': 'application/json'},
);
if (response.statusCode != 200) {
throw HttpException(
'Product request failed with status ${response.statusCode}',
);
}
final decoded = jsonDecode(response.body);
if (decoded is! List) {
throw const FormatException('Expected a JSON list');
}
return decoded;
}
class HttpException implements Exception {
const HttpException(this.message);
final String message;
@override
String toString() => message;
}When the request appears, select it to inspect its details. Look at the URL, method, status, headers, request and response data, and timing information. The exact fields can vary by Flutter and DevTools version.
Read failures systematically
Use the status code and timing as separate clues.
| Observation | Likely area to inspect |
|---|---|
| No request appears | The callback may not run, recording may be off, or the request uses unsupported platform-native networking |
| `400` or `422` | Request parameters or body may be invalid |
| `401` or `403` | Authentication or authorization may be missing or expired |
| `404` | The URL path or API version may be wrong |
| `500` or `503` | The server failed or is unavailable |
| Long duration | DNS, connection, server processing, payload size, or device network |
| `200` with a parsing error | The response body does not match the app's expected format |
Do not treat a 200 status as proof that the app received valid data. An API can return a success status with an error object, an empty result, or a changed JSON shape. Compare the response body with the model your Dart code expects.
A request can also fail before an HTTP response exists. Timeouts, DNS errors, certificate errors, and offline devices may appear as exceptions rather than status codes. Inspect the exception in the debugger or logs, then verify the device's connectivity and the target host.
Verify the fix
After changing the URL, headers, timeout, or response handling, clear or restart the recording if needed. Reproduce the same user action. Confirm that:
- The expected request appears.
- The method, URL, and important headers are correct.
- The response status and body match the contract.
- The UI handles both success and failure.
- The request does not repeat unexpectedly.
For a slow request, compare several runs. One slow sample does not prove a performance problem. If every run is slow, use the timing details to decide whether to investigate the server, payload, or client code. If the request is fast but the screen updates slowly, move to the Performance view instead.
Exercise
The Network view shows a 200 response, but the app throws a JSON parsing error. What should you inspect first?
Show answer
Inspect the response body and compare its actual JSON shape with the Dart code's expected shape. A successful HTTP status does not guarantee a valid application response.