dio_debug_logger 0.2.0
dio_debug_logger: ^0.2.0 copied to clipboard
In-app network inspector for Dio: draggable debug button, request list with search and filters, request/response details, stats, retry and cURL/Postman export.
dio_debug_logger #
An in-app network inspector for Dio. Adds a draggable debug button to your app that opens a full log viewer: request list with search and filters, request / response / error details, statistics, retry, and cURL / Postman / JSON export.
Setup takes two lines, and both are automatically disabled in release builds.
๐ฆ๐ฟ Azษrbaycan dilindษ
| Feature | |
|---|---|
| Draggable floating button with request/error badge | โ |
| Log list with search and status filter | โ |
| Request / Response / Error details with JSON tree view | โ |
| Statistics (success rate, slowest/fastest, by method) | โ |
| Copy as cURL / Postman / JSON / readable summary | โ |
| Retry a request | โ |
Sensitive header masking (Authorization, Cookie, โฆ) |
โ |
| Responsive (phone โ tablet, large fonts) | โ |
Installation #
flutter pub add dio_debug_logger
Setup (2 lines) #
import 'package:dio_debug_logger/dio_debug_logger.dart';
// 1) Record the requests of your Dio instance
final dio = Dio()..addDebugLogger();
// 2) Show the debug button
MaterialApp(
builder: DioDebugLogger.builder(),
home: const HomePage(),
);
That's it. Tap the ๐ button to open the logs.
- Both lines do nothing in release builds (
kDebugModeis the default), so you don't need to remove them before shipping. - No
navigatorKeyornavigatorObserversneeded โ the navigator is found automatically.
Already have a builder? #
Pass it in โ the debug button is placed on top of it:
MaterialApp(
builder: DioDebugLogger.builder(
builder: (context, child) => MediaQuery(
data: MediaQuery.of(context).copyWith(textScaler: TextScaler.noScaling),
child: child!,
),
),
);
Enable it in other environments #
Pass enabled to both lines, for example to show it in a staging build:
dio.addDebugLogger(enabled: isStaging);
MaterialApp(builder: DioDebugLogger.builder(enabled: isStaging));
Configuration #
DioDebugLogger.builder(
enabled: kDebugMode, // default
backgroundColor: Colors.indigo,
foregroundColor: Colors.white,
icon: Icons.bug_report_rounded,
buttonSize: 56,
showBadge: true, // request / error count
initialAlignment: Alignment.centerLeft,
snapToEdge: true, // snap to the nearest edge when released
);
dio.addDebugLogger(
enabled: kDebugMode, // default
printToConsole: kDebugMode, // default
redactSensitiveHeaders: true, // mask Authorization etc. in the console
maxConsoleBodyLength: 2000,
);
// How many requests are kept in memory (default 200)
DioDebugLogger.configure(maxRequests: 500);
// Use your own Dio for the "Retry" button (certificate pinning, base options, ...)
DioDebugLogger.retryClientBuilder = () => myDio;
Opening the logs from code #
DioDebugLogger.open(context);
DioDebugLogger.close(context);
DioDebugLogger.isOpen; // bool
DioDebugLogger.isOpenNotifier; // ValueListenable<bool>
Accessing the logs directly #
final storage = DioDebugLogger.storage; // singleton ChangeNotifier
storage.count;
storage.errorCount;
storage.successCount;
storage.pendingCount;
storage.averageElapsedMs;
storage.requests; // List<DebugModel>, newest first
storage.setRecording(false); // pause recording
storage.clear();
storage.deleteById(id);
storage.exportAll(redact: true); // List<Map<String, dynamic>>
What's on the log page #
- Search by URL, method or status code
- Filter โ All / Success / Errors / Pending
- Multi-select โ long press to select, delete in bulk
- Swipe to delete a single log
- โฎ menu โ Analytics, Pause recording, Copy all as JSON, Clear all
- Details โ Request / Response / Error tabs, JSON tree โ raw text, headers, size and duration
- Copy โ cURL, Postman collection, JSON, readable summary, response body only
(the Hide tokens switch masks
Authorization/Cookie) - Retry โ resend the request and see the result in place
Security notes #
- Sensitive headers (
Authorization,Cookie,X-Api-Key, โฆ) are masked in console output, in copied text (when Hide tokens is on, the default) and inexportAll(). - The UI shows headers in full โ this is a developer tool. Keep it disabled in production (the default).
Migrating from 0.1.x #
The old API still works but is deprecated:
| Old | New |
|---|---|
dio.interceptors.add(DebugLogging()) |
dio.addDebugLogger() (the old form is still fine) |
NetworkLogger.overlayBuilder(...) |
DioDebugLogger.builder(...) |
NetworkLogger.open/close/... |
DioDebugLogger.open/close/... |
openDebugPage(context) |
DioDebugLogger.open(context) |
Note:
NetworkLogger.overlayBuilder()was enabled by default;DioDebugLogger.builder()is only enabled in debug builds unless you passenabled.
License #
MIT