flutter_network_throttler 1.1.0
flutter_network_throttler: ^1.1.0 copied to clipboard
Simulate slow, unreliable, or failing network conditions in Flutter apps to test loading, timeout, and error states.
1.1.0 #
A feature + reach release. No breaking changes — every new field defaults to the previous behaviour.
Wider compatibility #
- Lowered the SDK floor from
sdk: ^3.12.2tosdk: ^3.8.0(flutter: ">=3.32.0"), so the package resolves for the whole modern Dart 3 ecosystem instead of only the newest toolchain. (3.8 is the true minimum — the panel uses null-aware elements, wildcard parameters, andDropdownButtonFormField.initialValue, all introduced after Dart 3.0.)
New simulation features #
- Connection-setup delay —
NetworkCondition.connectionSetupmodels the one-off DNS + TLS + connect cost, applied before per-request latency. The mobile presets now include realistic values. - Latency distributions —
LatencyDistribution.uniform/gaussian/longTailshape the jitter draw;3G/2Gdefault to long-tail. - 429 / Retry-After — new
FailureType.http429synthesizes a 429 carrying aRetry-Afterheader (configurable viaFailureInjection.retryAfter) for rate-limit/back-off testing. - Response tampering —
ResponseTampering(truncate / corrupt bytes / garbage body) damages a fraction of successful responses to test parser robustness. - Richer endpoint rules —
EndpointRulegainshost,query, andheadersmatchers and ananchoredflag (substring matching is still the default).
HTTP adapter #
- Streaming responses —
ThrottleClientnow streams the response body through with the bandwidth cap applied progressively per chunk instead of buffering the whole payload in memory. Opt back into buffering withThrottleClient(..., streamResponses: false).
UI #
- Panel decomposed into per-section sub-widgets under
src/ui/panel/for maintainability (public API unchanged). - New controls: connection-setup slider, jitter-shape selector, Retry-After slider (429), and a Response-tampering section.
NetworkThrottlerScope— a framework-agnosticInheritedNotifierfor providing the controller to a subtree (works alongside provider / Riverpod / Bloc, no extra dependency).
Testing #
- Real golden assertions (
matchesGoldenFile) for the panel, with a tolerant comparator so they run on any platform. - The screenshot generator now loads checked-in Roboto fonts, so it runs everywhere instead of skipping off macOS.
- Added concurrency, streaming, tampering, 429, distribution, and rule-matching tests.
1.0.0 #
Initial release.
Models #
-
NetworkConditiondescribing latency, jitter, bandwidth, and packet loss, with presetsperfect,wifi,fourG,threeG,twoG, andoffline. -
FailureInjection+FailureType(timeout / 500 / 403 / no-connection) for injecting specific failures into otherwise-healthy requests. -
EndpointRulewith glob matching andDelayAction/FailAction/PassThroughActionfor per-endpoint overrides. -
RequestLogEntry/ThrottleProfilefor captured traffic and the full config. -
JSON serialisation (
toJson/fromJson) on every model.
Engine #
ThrottleEngine— adapter-agnostic decision core (latency, packet loss, failure injection, rule precedence, bandwidth math).ThrottleController— aChangeNotifiersource of truth with a capped live request log; the thing the UI binds to and the adapters read. Includes saved custom presets, capture pause,ThrottleMetrics, and optional persistence.
Adapters #
ThrottleClient— a drop-inpackage:httpBaseClientwrapper.ThrottleInterceptor— apackage:diointerceptor, viapackage:flutter_network_throttler/dio.dart.ThrottleWebSocketChannel— aWebSocketChannelwrapper that throttles the handshake and individual frames, viapackage:flutter_network_throttler/web_socket.dart. Frames are taggedWS/WS↑/WS↓in the live log. UseThrottleWebSocketChannel.connect()to open and throttle a connection in one call.ThrottleStreamTransformer— throttle anyStream(gRPC, SSE, event buses).
Persistence, scenarios, DevTools #
ThrottleStorage/CallbackThrottleStorage— plug in any backing store; the controller restores on startup and saves on change.ThrottleScenario— script timed conditions, with anofflineForhelper and optional looping.registerThrottleServiceExtensions— drive the controller from Flutter DevTools; no-ops in release.
UI #
NetworkThrottlerPaneldebug control panel matching the design. Present it as a bottom sheet (showNetworkThrottlerPanel, now with a drag handle), a full-screen page with a back button (NetworkThrottlerPage/showNetworkThrottlerPage), or embedded directly.NetworkThrottlerButton— akDebugMode-gated launcher (FAB or custom trigger) that opens the panel and disappears in release builds.- Live-log metrics strip, HTTP/WS/failed filters, pause & clear, and tap-to-inspect; an in-panel rule editor; "Save current" custom presets.
Core #
NetworkThrottler.throttle()genericFuturewrapper andSimulatedNetworkException, with deterministic behaviour via an optional randomseed.
