How bayunugroho2022/dio-request-inspector works
Project Type and Purpose
• This is a Flutter plugin package (“dio_request_inspector”) that hooks into the Dio HTTP client to intercept, log, secure, filter, and display HTTP activity in a built-in UI.
• It exposes a NavigatorObserver and a Dio interceptor, plus a widget wrapper, to integrate seamlessly into any Flutter app.
File-Structure Analysis
• Top level
– example/ : demo Flutter app showing how to integrate the plugin
– lib/ : the plugin code itself
– test/ : unit tests for core functionality
– .github/, README.md, etc. – CI, contribution guidelines, documentation
• lib/src/ breakdown
– common/ : utilities (copy, enum types, extensions, helpers, parser, local storage)
– interceptor.dart : logic to create a DioInterceptor that captures requests, responses, errors
– model/ : data classes for HTTP request, response, error, activity, form-data
– page/ : UI layer
• main/ : entry widget (DioRequestInspectorMain) that wraps the app and installs the NavigatorObserver
• dashboard/ : list view of all captured activities (filters, search, summary toggle)
• detail/ : per-activity detail view (headers, JSON beautification, copy/share)
• lib/dio_request_inspector.dart
– Public API: exposes DioRequestInspector, navigatorObserver, DioRequestInspectorMain wrapper
README Insights
• Core feature list: intercept + log + secure (password) + filter + search + share + beautify + UI
• Integration steps:
1. wrap your root widget with DioRequestInspectorMain
2. DioRequestInspector.navigatorObserver to navigatorObservers
3. Plugin’s interceptor to your Dio instance
Diagramming the Architecture
a. Main Components
– Integration Layer
• DioRequestInspectorMain widget (root)
• NavigatorObserver (for long-press detection, hide/show UI)
• PasswordProtection (optional)
– Interceptor Layer
• DioInterceptor (intercepts request/response/error events from Dio)
– Data Layer
• Storage Manager (in-memory or persisted via common/storage.dart)
• Parser & Helpers (format JSON, extract form-data)
– Model Layer
• HTTPActivity (ties request + response + error)
• HttpRequest, HttpResponse, HttpError, FormData
– UI Layer
• DashboardPage (list, filters, search, summary)
• DetailPage (per-entry details, copy/share)
• Widgets (dot indicator, item rows/columns, password dialog)
– External Dependencies
• Dio HTTP client
• Flutter MaterialApp + Navigator
b. Relationships & Data Flow
– App code → wraps with DioRequestInspectorMain → installs NavigatorObserver
– App code → Dio instance → plugin’s interceptor → onRequest/onResponse/onError callbacks
– Interceptor → Storage Manager → emits events (Activity list updated)
– UI (DashboardPage) subscribes to storage events → renders list
– User taps an item → navigates to DetailPage with selected HTTPActivity
– User actions (copy/share) → Common helpers invoked
c. Architectural Patterns/Principles
– Layered Architecture: separation of Interceptor, Data, Model, UI
– Observer Pattern: storage broadcasts changes to UI
– Dependency Injection (NavigatorObserver, interceptor)
– Single-Responsibility for parser, storage, model, UI widgets
d. Technologies & Frameworks
– Flutter (UI)
– Dio (HTTP client)
– Provider / built-in setState or Streams (implicit state management)
– JSON parsing (dart:convert + custom parser)