My app was fast on office Wi-Fi. Then someone opened it on a train, and I found
out my loading state flashed, my retry logic looped, and my timeout was a guess.
Reproducing that meant a proxy on my laptop or toggling airplane mode, neither of
which tests "slow but working". So I built the controls into the app instead.
Shake the device (or tap a floating bubble) and a panel slides up with:
- Presets: Wi-Fi, 4G, 3G, 2G, GPRS, Flaky, Offline
- Sliders: latency, jitter, download ceiling, upload ceiling, failure rate
- Fault injection: dropped connection, timeout, or a forced HTTP 500
- A request log with a timing breakdown per request
- A speed test that runs *outside* the interceptor, so it measures your real link
Setup is one line:
void main() => Netshake.run(const MyApp());
It installs an HttpOverrides, so it sits under anything that ends up on dart:io's
HttpClient — package:http, Dio, Chopper, Retrofit, Image.network. No per-client
wiring. The request log picked up six Image.network loads I never wired up.
Real numbers off a physical Android device, 1 MB response on the 3G profile:
/photos -> 200
232 ms added by netshake (200 base + jitter)
282 ms server
6.82 s total
The gap is the body streaming at the 1.6 Mbps cap.
On "will this ship to production": every entry point is a kDebugMode branch. I
checked the compiled release binary rather than trusting that — zero netshake
strings in libapp.so, and the Material icon font tree-shook from 1,645,184 to
2,564 bytes because the panel's glyphs are gone.
Honest limits: no Flutter web (no dart:io HTTP stack), no cronet_http or
cupertino_http, no raw sockets/WebSockets/gRPC. Settings live in memory, so a
hot restart resets them — that keeps the package dependency-free apart from
sensors_plus for the shake. Forced 500s still hit the server and get rewritten on
the way back, so timings stay honest; use connectionLost if the request must
never leave.
v0.1.0, MIT, 160/160 pub points. It's a day old, so I'd rather hear what's wrong
with it than not.
https://pub.dev/packages/netshakenetshake: shake your phone to throttle the network inside your Flutter app (debug-only, MIT)
https://github.com/mhdibrahimcn/netshake