netguard 2.0.0
netguard: ^2.0.0 copied to clipboard
A Dio-based HTTP client for Flutter with caching, connectivity handling, auth token refresh, retries and certificate pinning.
2.0.0 - 2026-08-31 #
💥 Breaking #
- Non-2xx responses throw again. 1.x forced
validateStatus: (s) => s < 600, sotry/catchnever fired. Opt out withoptions.resolveErrorStatuses = true. - Offline requests throw
NetworkOfflineExceptioninstead of returning a fabricated503body. ChooseOfflineBehavior.fail/.wait/.queue. response.isRedirect→isRedirection. Dio'sResponsedeclares its ownisRedirectfield, which shadowed the 1.x extension getter.IOHttpClientAdaptermoved topackage:netguard/io.dart, keeping the main entry point web-safe.
⚠️ Deprecated (still work, removed in 3.0.0) #
| Deprecated | Use instead |
|---|---|
encryptionFunction |
bodyEncoder |
encryptBody: |
encodeBody: |
useCache: true |
cachePolicy: CachePolicy.staleWhileRevalidate |
throwOnOffline = true |
offlineBehavior = OfflineBehavior.fail |
throwOnOffline = false |
offlineBehavior = OfflineBehavior.wait |
autoRetryOnNetworkRestore = true |
offlineBehavior = OfflineBehavior.queue |
maxNetworkRetries = n |
retryPolicy = RetryPolicy(maxAttempts: n) |
networkRetryDelay = d |
retryPolicy = RetryPolicy(initialDelay: d) |
showLogs = true |
logLevel = NetGuardLogLevel.verbose |
showLogs = false |
logLevel = NetGuardLogLevel.error |
bodyEncoder was renamed because the default is base64 encoding, not
encryption — it provides no confidentiality.
🐞 Fixed #
configureAuth()doubled the interceptor chain on every call (1 → 3 → 5 → 9).options.configureAuth(...)silently did nothing — the client and its options each built a separateAuthManager.handleNetwork = truewas a no-op on every client not built withfromDio.- Typed requests threw
_TypeErrorwhile offline. - The auth queue always threw — it cast between two sibling handler types.
- Every cache miss issued two identical requests.
- Cache keys omitted base URL and method, and depended on query ordering.
- Web clients reported themselves permanently offline.
- The cache selected the
dart:iostore under wasm. token.substring(0, 20)threwRangeErroron short tokens, and leaked credentials into logs.AuthInterceptor.clear()threwStateErrorafter a settled refresh.- Queued requests produced unhandled async errors.
NetworkService.dispose()left a permanently dead singleton.getUridiscarded the URI's own query parameters.- Cache, connectivity and auth errors were logged at a level that never printed.
- Auth replays went through a throwaway
Dio(), skipping your interceptors.
✨ Added #
- Cache policies (
cacheFirst,networkFirst,staleWhileRevalidate,cacheOnly),ETag/304revalidation, and pattern invalidation. RetryPolicy— exponential backoff, jitter,Retry-After, idempotent-only.- Request deduplication for identical in-flight GETs.
- Persistent offline queue with idempotency keys, surviving restarts.
- Proactive token refresh from the JWT
expclaim. - Certificate pinning via
pinCertificates(...). NetGuardLoggerwith levels, a pluggable sink and credential redaction;enableLogging(emitCurl: true).- Typed decoding with
getAs/postAs, plusapiError/apiMessage. - Cancellation groups, rate limiting, and per-request metrics.
🔧 Changed #
- All verbs share one request pipeline, so caching, connectivity, retry, deduplication and metrics behave identically everywhere.
- Connectivity no longer pings
google.com,cloudflare.comandhttpbin.orgon every network change. Configure a probe against your own endpoint instead. - dio 5.11. Test suite rewritten against a mock adapter (53 tests).
1.0.4 - 2026-02-04 #
🔧 Maintenance & Bug Fixes #
- Fixed all
"token log issuwarnings and hints across the library.
1.0.3 - 2026-01-12 #
🔧 Maintenance & Bug Fixes #
- Fixed all
dart analyzewarnings and hints across the library and examples. - Standardized
LICENSEfile to standard MIT format for better package recognition on pub.dev.
1.0.2 - 2026-01-12 #
🔧 Maintenance #
- Updated
connectivity_plusto^7.0.0to support the latest stable version and satisfy package analysis requirements.
1.0.1 - 2026-01-06 #
✨ New Features #
- Added
isLoginparameter to request methods.- Prevents automatic token refresh loops on 401 errors during login.
- Bypasses offline queueing for login requests.
- Added
showLogsoption toNetGuardOptions.- Allows toggling verbose logging on/off.
- Critical errors are still shown even if logs are disabled.