chucker_flutter_plus 1.1.8
chucker_flutter_plus: ^1.1.8 copied to clipboard
In-app HTTP inspector for Flutter with request history, notifications, and shared logging for Dio, Chopper, and package:http.
Chucker Flutter Plus #

Capture and inspect HTTP traffic inside your Flutter app. Chucker Flutter Plus
stores a bounded local request history, shows in-app banners, and can post
optional system notifications. It supports Dio and package:http capture, plus
a separate console logger for Dio, Chopper, and package:http.
Install #
flutter pub add chucker_flutter_plus
Capture requests #
Initialize the inspector and console logger once before runApp. Add its
navigator observer to your MaterialApp so in-app banners can attach to the
app overlay and notification taps can open the selected request.
import 'package:chucker_flutter_plus/chucker_flutter_plus.dart';
import 'package:chucker_flutter_plus/network_logger_dio.dart';
import 'package:dio/dio.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await ChuckerFlutterPlus.initialize(
enableNotifications: true,
showInAppNotification: true,
showStatusBarNotification: true,
statusBarWhileForeground: false,
inAppNotificationDuration: Duration(seconds: 3),
inAppNotificationPosition: BannerPosition.top,
notifyOnlyOnError: false,
maximumEntries: 200,
enableOnRelease: false,
);
final logger = NetworkLogger(
config: const NetworkLogConfig(
enableOnRelease: false,
logRequestHeaders: true,
logRequestBody: true,
logResponseHeaders: true,
logResponseBody: true,
logErrorBody: true,
logCurlCommand: true,
maxBodyLength: 4000,
slowRequestThreshold: Duration(seconds: 3),
),
printer: debugPrint,
);
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) => MaterialApp(
navigatorObservers: [ChuckerFlutterPlus.navigatorObserver],
home: const HomePage(),
);
}
final dio = Dio()
..interceptors.add(ChuckerDioInterceptor())
..interceptors.add(DioNetworkLoggerInterceptor(logger: logger));
For package:http, wrap a client:
import 'package:chucker_flutter_plus/chucker_flutter_plus.dart';
import 'package:http/http.dart' as http;
final client = ChuckerHttpClient(http.Client());
final response = await client.get(Uri.parse('https://example.com/items'));
ChuckerHttpClient returns the response stream immediately while forwarding
each chunk to the caller. It retains at most 1 MiB for inspector capture; larger
responses are marked truncated in history. Streamed downloads and SSE responses
are not buffered before delivery.
The inspector, local history, request capture, and console logger support Android, iOS, Linux, macOS, and Windows. The package requires Flutter 3.44 or later. It has no native implementation of its own; desktop support uses the Flutter and dependency plugins.
To enable desktop builds in an app, generate its runners from the app directory:
flutter create --platforms=linux,macos,windows .
Build each target on its supported host platform. Linux builds also require the GTK 3 development packages listed in Flutter's Linux setup guide.
HTTP compression #
Compression is negotiated by the HTTP client; Chucker does not compress requests or responses. With the default clients, gzip compression works across the native platforms:
| Platforms | Default behavior |
|---|---|
| Android, iOS, Linux, macOS, Windows | Dio's native adapter and package:http's IOClient use Dart HttpClient, which requests gzip and decompresses gzip responses automatically. |
| Web | Dio's browser adapter and package:http's BrowserClient leave negotiation and decompression to the browser. The browser controls Accept-Encoding. |
No platform-specific Chucker setup is needed. Custom Dio adapters or custom
package:http clients may use different compression behavior. Dart's native
HttpClient automatically decompresses gzip; other encodings depend on the
underlying client. See the Dart HttpClient compression docs,
Dio adapters,
and package:http client implementations.
When a response includes Content-Length, Chucker uses that value for the
reported response size. For compressed responses this can be the smaller wire
size, while the body exposed to the app has already been decompressed. If the
length is absent, Chucker falls back to the observed body size.
Gzip usually saves network transfer for text and JSON, at the cost of CPU time
to compress and decompress. It usually adds little benefit for already
compressed formats such as JPEG, PNG, MP4, or ZIP. Chucker adds its own cost
when capture is enabled: it observes response bodies and retains at most 1 MiB
per response. This bounded copy does not limit the response delivered to your
app. ChuckerHttpClient starts delivering streamed responses without waiting
for the stream to finish.
Open the inspector #
Add the built-in button to a widget:
ChuckerFlutterPlus.button()
Or open the inspector directly. Pass a request ID to open that request's details page:
ChuckerFlutterPlus.showInspector(context);
ChuckerFlutterPlus.showInspector(context, requestId);
Use ChuckerFlutterPlus.hideInspector() to close it. The inspector also
provides methods to clear history and export it as JSON:
await ChuckerFlutterPlus.clearLogs();
final json = await ChuckerFlutterPlus.exportLogs();
Performance dashboard #
Open the inspector menu and choose Performance dashboard to review the captured request history. The dashboard includes average and P95 latency, success and error rates, total response data, recent latency distribution, request volume over the last hour, status code ratios, and call counts by HTTP method and host. Host latency summaries highlight the slower services.
These statistics are calculated from the requests currently retained in local
history. Response data totals use the captured response sizes, which may use a
server-provided Content-Length where available.
Compare requests
Choose Compare two requests in the inspector menu, then tap two captured requests. The comparison view places their URLs, methods, status, duration, transfer sizes, headers, and response bodies side by side. Different values are highlighted to make regressions and environment differences easier to spot.
Internet speed test #
Open a built-in screen to measure latency, download speed, and upload speed:
ChuckerFlutterPlus.showSpeedTest(context);
The default test endpoints use Cloudflare's public speed test service. You can
pass your own compatible endpoints with downloadUrl, uploadUrl, and
latencyUrl when your app uses a private test server.
Image and video responses #
Responses with an image/* or video/* content type get a Media tab. Images
are previewable and can be opened larger by tapping the preview. Video responses
play inline from their URL when the URL is directly accessible. Playback does
not reuse captured authentication headers: those values are redacted before
storage, and the video player does not attach request headers. Auth-protected or
signed URLs with redacted query values may therefore fail to play. Media bodies
up to 1 MiB are retained for previews. Larger media bodies are truncated in
history while the recorded response size remains available.
Notifications #
In-app banners appear while the app is in the foreground. The setup above
enables OS notifications for background requests and configures both delivery
types. Set showStatusBarNotification to false to disable OS notifications.
On Android 13 and later, add the notification permission to the host app's
android/app/src/main/AndroidManifest.xml; the package also requests runtime
permission during initialization:
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
Android notifications default to @mipmap/ic_launcher, which resolves the
standard Flutter launcher icon under
android/app/src/main/res/mipmap-*/ic_launcher.png. To use a custom icon,
add a drawable resource under android/app/src/main/res/drawable/ (for example
ic_notification.xml or .png) and pass its resource name without extension,
or reference a mipmap resource with @mipmap/<name>:
await ChuckerFlutterPlus.initialize(
enableNotifications: true,
androidNotificationIcon: 'ic_notification',
);
You can also configure androidNotificationIcon on InspectorConfig. If the
configured icon resource is missing on Android, initialization logs a warning
and disables status bar notifications gracefully instead of throwing.
iOS and macOS use the app icon and request notification permission during initialization. Linux and Windows use their desktop notification services. Notification tap routing depends on the platform notification service and may not be available on every desktop environment.
Chucker notification payloads use the stable plain-text format
chucker:<percent-encoded-request-id>. Chucker handles its own notification
responses and opens the inspector on the matching request. If your app also
handles local notification responses, check Chucker's payload before passing
the payload to an app JSON decoder:
void handleNotificationTap(String? payload) {
if (ChuckerFlutterPlus.handleNotificationPayload(payload)) return;
if (payload == null) return;
try {
// Decode and handle this app's normal JSON notification payload.
final data = jsonDecode(payload);
handleAppNotification(data);
} on FormatException {
handleUnknownNotification(payload);
}
}
The method returns false for payloads not created by Chucker. Chucker-prefixed
payloads are consumed even if malformed, preventing them from reaching an app's
JSON decoder. For custom request IDs, use
ChuckerNotificationPayload.encode(requestId) and
ChuckerNotificationPayload.tryParse(payload) to encode and safely recognize
the format.
Console logging #
NetworkLogger is independent from inspector capture. Create one instance and
share it across your network clients. Logging is enabled in debug builds by
default. Use enableOnRelease: true to enable it in release builds, or
forceLogging: true to override both the build mode and enabled: false.
import 'package:flutter/foundation.dart';
import 'package:chucker_flutter_plus/network_logger.dart';
final logger = NetworkLogger(
config: const NetworkLogConfig(
enableOnRelease: false,
logRequestHeaders: true,
logRequestBody: true,
logResponseHeaders: true,
logResponseBody: true,
logErrorBody: true,
logCurlCommand: true,
maxBodyLength: 4000,
slowRequestThreshold: Duration(seconds: 3),
),
printer: debugPrint,
);
Use the matching adapter for each client:
import 'package:chopper/chopper.dart' as chopper;
import 'package:chucker_flutter_plus/dio_network_logger.dart';
import 'package:chucker_flutter_plus/chopper_network_logger.dart';
import 'package:chucker_flutter_plus/http_network_logger.dart';
import 'package:dio/dio.dart';
import 'package:http/http.dart' as http;
final dio = Dio()
..interceptors.add(DioNetworkLoggerInterceptor(logger: logger));
final chopper = ChopperClient(
interceptors: [ChopperNetworkLoggerInterceptor(logger: logger)],
);
final loggedHttp = LoggingHttpClient(
inner: http.Client(),
logger: logger,
);
The console logger redacts common credential headers and sensitive JSON keys
by default. Customize them with NetworkLogConfig.sensitiveHeaders,
NetworkLogConfig.sensitiveJsonKeys, or a LogRedactor:
final logger = NetworkLogger(
redactor: const LogRedactor(
sensitiveHeaders: {'authorization', 'x-session-id'},
sensitiveJsonKeys: {'password', 'access_token', 'private_note'},
),
);
Disable logging for an individual request with the adapter's control:
// Dio
dio.get('/private', options: Options(extra: {
DioNetworkLoggerInterceptor.disableLoggingExtraKey: true,
}));
// Chopper
final privateChopperRequest = chopper.Request(
'GET',
Uri.parse('/private'),
Uri.parse('https://api.example.com'),
tag: const NetworkLoggerDisabled(),
);
// package:http: the control header is removed before sending.
final privateHttpRequest = http.Request('GET', uri)
..headers[LoggingHttpClient.disableLoggingHeader] = 'true';
LoggingHttpClient preserves response streaming and logs after the stream is
read. It does not consume a StreamedRequest body to inspect it.
Privacy and retention #
Inspector capture is enabled in debug builds by default. Set
enableOnRelease: true during initialization, or call
ChuckerFlutterPlus.configure(enableOnRelease: true), to enable capture in
release builds. Set maximumEntries and retention to bound local history.
Request headers are redacted before storage. Defaults include Authorization,
Cookie, Set-Cookie, x-api-key, and api-key; configure additional headers
with redactHeaders:
await ChuckerFlutterPlus.initialize(
redactHeaders: {'authorization', 'cookie', 'x-api-key'},
);
Sensitive JSON keys, sensitive URL query parameters, multipart field values, and x-www-form-urlencoded request fields are redacted before storage. Customize the header and body rules and replacement marker at initialization:
await ChuckerFlutterPlus.initialize(
redactHeaders: {'authorization', 'cookie', 'x-api-key', 'x-session-id'},
redactBodyKeys: {
'password', 'access_token', 'refresh_token', 'email', 'private_note',
},
redactionReplacement: '[hidden]',
);
InspectorConfig exposes the same redactHeaders, redactBodyKeys, and
redactionReplacement options for configuration-object setup. Key matching is
case and punctuation insensitive, including nested JSON objects and lists.
Unstructured non-JSON text bodies are kept as captured because their structure
cannot be reliably inspected. Multipart file bytes are not interpreted as
text; field values are redacted in the stored preview.
Request and response bodies are stored for inspection. Review the data your app sends before enabling capture or console logging in production.
Development #
dart format .
flutter analyze
flutter test