What is the use of Network Inspector plugin in Flutter? Provide examples.
#flutter#networking#debugging#devtools#dio#inspector
Answer
Overview
There is no single "Network Inspector plugin" in Flutter. The term refers to several tools that let you inspect HTTP requests/responses in your Flutter app — from the built-in Flutter DevTools Network tab to third-party in-app inspector packages.
1. Flutter DevTools Network Tab (Built-in, Official)
The Network View is a built-in tab in Flutter DevTools. It captures HTTP, HTTPS, and WebSocket traffic automatically — no package installation needed.
How to Use (Step by Step)
text1. Run your app: flutter run 2. Open DevTools: - VS Code: Ctrl+Shift+P > "Dart: Open DevTools" - Android Studio: DevTools button in toolbar 3. Navigate to the "Network" tab 4. Recording starts automatically 5. Interact with your app — all API calls appear in the list 6. Click any request to see details
What You Can Inspect
| Info | Details |
|---|---|
| General | URL, HTTP method, status code |
| Timing | Request start/end time, duration |
| Request Headers | All sent headers |
| Request Body | Payload sent with the request |
| Response Headers | All received headers |
| Response Body | JSON, text, images |
Filtering Requests
textm:get → Filter by GET method s:404 → Filter by status code 404 t:json → Filter by JSON response type my-endpoint m:post s:200 → Combined filters
Capture Startup Traffic
bashflutter run --start-paused # Open DevTools > Network tab > Resume app
2. Dio with LogInterceptor (Console Logging)
Dio's built-in
text
LogInterceptordartimport 'package:dio/dio.dart'; final dio = Dio(); dio.interceptors.add(LogInterceptor( request: true, requestHeader: true, requestBody: true, responseHeader: true, responseBody: true, error: true, )); // All requests logged to console final response = await dio.get( 'https://jsonplaceholder.typicode.com/posts/1', );
3. textpretty_dio_logger
(Better Console Formatting)
text
pretty_dio_loggerdartimport 'package:dio/dio.dart'; import 'package:pretty_dio_logger/pretty_dio_logger.dart'; final dio = Dio() ..interceptors.add( PrettyDioLogger( requestHeader: true, requestBody: true, responseBody: true, responseHeader: false, error: true, compact: true, ), );
4. textalice
(Full In-App HTTP Inspector)
text
alicetext
alicedartimport 'package:alice/alice.dart'; import 'package:dio/dio.dart'; // Create Alice instance Alice alice = Alice( showNotification: true, // Notification overlay showInspectorOnShake: true, // Shake to open ); // Set navigator key in MaterialApp MaterialApp( navigatorKey: alice.getNavigatorKey(), home: const HomeScreen(), ); // Add Alice interceptor to Dio final dio = Dio(); dio.interceptors.add(alice.getDioInterceptor()); // Make requests — they appear in Alice UI await dio.get('https://jsonplaceholder.typicode.com/users'); await dio.post('https://jsonplaceholder.typicode.com/posts', data: {'title': 'Hello', 'body': 'World'}); // Manually open inspector alice.showInspector();
5. textchucker_flutter
(Cross-Platform Inspector)
text
chucker_flutterInspired by Android's Chucker — shows in-app notifications with status codes and a JSON tree view.
dartimport 'package:chucker_flutter/chucker_flutter.dart'; import 'package:dio/dio.dart'; // Add navigator observer MaterialApp( navigatorObservers: [ChuckerFlutter.navigatorObserver], home: const HomeScreen(), ); // Add interceptor to Dio final dio = Dio(); dio.interceptors.add(ChuckerDioInterceptor()); // Requests appear as notifications in the app await dio.get('https://api.example.com/users');
6. Custom Dio Interceptor (Write Your Own)
dartimport 'package:dio/dio.dart'; class NetworkLogInterceptor extends Interceptor { void onRequest(RequestOptions options, RequestInterceptorHandler handler) { print('→ REQUEST[${options.method}] ${options.path}'); print(' Headers: ${options.headers}'); if (options.data != null) print(' Body: ${options.data}'); handler.next(options); } void onResponse(Response response, ResponseInterceptorHandler handler) { print('← RESPONSE[${response.statusCode}] ${response.requestOptions.path}'); print(' Data: ${response.data}'); handler.next(response); } void onError(DioException err, ErrorInterceptorHandler handler) { print('✖ ERROR[${err.response?.statusCode}] ${err.requestOptions.path}'); print(' Message: ${err.message}'); handler.next(err); } } // Usage final dio = Dio(); dio.interceptors.add(NetworkLogInterceptor());
Comparison of Network Inspection Tools
| Feature | DevTools Network | text | text | text |
|---|---|---|---|---|
| In-app UI | No (external) | ✅ Yes | ✅ Yes | No (console) |
| Shake to open | N/A | ✅ Yes | No | N/A |
| Notification overlay | N/A | ✅ Yes | ✅ Yes | N/A |
| Dio support | ✅ Auto | ✅ Yes | ✅ Yes | ✅ Yes |
| http package support | ✅ Auto | ✅ Yes | ✅ Yes | No |
| Export/share logs | No | ✅ Yes | ✅ Yes | No |
| Works in release | No | ✅ Yes | Configurable | ✅ Yes |
| Setup complexity | Zero | Medium | Low | Low |
When to Use Which
- During development/debugging → Flutter DevTools Network tab (zero setup)
- QA/testing builds → ortext
alice(in-app UI, shareable)textchucker_flutter - Quick console logging → ortext
pretty_dio_loggertextLogInterceptor - Custom logging needs → Write your own Dio interceptor
Important: DevTools Network tab only works in debug mode. For inspecting network calls in release/profile builds, use in-app tools like
ortextalice.textchucker_flutter
Learn more at Flutter DevTools Network View and alice package.