app_smart_network 1.2.0
app_smart_network: ^1.2.0 copied to clipboard
A smart Flutter network package with built-in error handling, configurable retry, and multilingual error messages (en/ar).
1.2.0 #
Features #
- Configurable retry —
NetworkConfignow accepts aretrypolicy.RetryPolicyexposesattempts,delays,methodsandstatuses, all of which were previously hardcoded. Passretry: nullto disable retry app-wide. - Per-request retry —
request(),download()anduploadFile()take aretry:argument that overrides the app-wide policy for a single call. UseRetryPolicy.offto opt one request out, or a policy with a higherattemptsto opt one in. - New public export —
RetryPolicy.
Changes #
- Retry defaults are unchanged: three retries on idempotent methods with a
1 s / 2 s / 3 s backoff. Code that does not mention
retrybehaves exactly as it did in 1.1.0.
Notes #
RetryPolicy.delaysandRetryPolicy.methodsare read from the app-wide policy only. Backoff is fixed when the client is built and cannot vary per request; the method allowlist guards calls that did not supply a policy, so a policy attached to a request bypasses it — that is what makesretry: RetryPolicy(attempts: 5)retry a POST.attemptsis capped atRetryPolicy.maxAttempts(10), asserted at construction.
1.1.0 #
Features #
- Custom interceptors —
NetworkConfignow accepts aninterceptorslist. They are registered before the built-in retry interceptor, the 401 handler, and the debug logger. A custom interceptor can therefore handle a 401 beforeonUnauthorizedfires, and itsonErrorfires once per genuine attempt on a retried request instead of receiving a duplicate replay of the same terminal failure (which is what happens to interceptors positioned after retry). - New public exports —
Interceptor,InterceptorsWrapper,QueuedInterceptor,QueuedInterceptorsWrapper,RequestOptions,RequestInterceptorHandler,ResponseInterceptorHandler,ErrorInterceptorHandler,DioException,DioExceptionTypeandResponseTypeare re-exported, so writing most interceptors no longer requires a directdiodependency.
Changes #
- The debug logger interceptor moved to the end of the interceptor chain. Debug output now reflects the final request after every interceptor has run. Debug builds only — no effect on release builds.
1.0.5 #
Bug fixes #
ErrorHandler—DioExceptionType.transformTimeoutnow returns a proper localized message (TransformTimeout) with status408, instead of leaking the raw'transformTimeout'key as the user-facing message.
Maintenance #
equatabledependency removed frompubspec.yaml. It was left behind after theFailureclasses were deleted in 1.0.3 and is no longer used.- Removed the unused
ConnectionErrorlocale key (bothenandar);connectionErrormaps toNoInternetConnection, so the key was dead.
1.0.4 #
1.0.3 #
Breaking changes #
-
ServerFailureandCacheFailureremoved —failures.dartand its public exports have been deleted. TheFailureabstraction was out of scope for a network package; it leaked domain-layer concerns into the library and forced an unnecessaryequatabledependency on consumers.-
Migration: catch
ApiExceptiondirectly in your repository layer, or define your ownFailuretypes and map fromApiExceptionthere.// before } on ApiException catch (e) { return Left(ServerFailure.fromException(e)); } // after – option A: catch ApiException directly } on ApiException catch (e) { return Left(MyServerFailure(e.message, e.statusCode)); }
-
-
equatabledependency removed — the package no longer depends onequatable. Remove it from your ownpubspec.yamlif you were relying on the transitive export.
1.0.2 #
Bug fixes #
ErrorHandler.handleErrornow passes anApiExceptionthrough unchanged instead of re-wrapping it as a generic'UnexpectedError'(status 0). This prevented the real error type, status code, and message from reaching callers whenever anApiExceptionentered the catch block (e.g. thrown by a custom interceptor).RequestService.execute—ensureConnected(),withMobileTimeouts(), andresolveUrl()are now inside the singletry/catchblock, so every error type (connectivity, timeout, bad response, certificate, cancel) flows throughErrorHandlervia one consistent code path.
1.0.1 #
Bug fixes #
ApiService.instancenow throws aStateErrorinstead of silently creating a broken client wheninitialize()has not been called yet.ApiService.isInitializedgetter added — use it to safely check whetherinitialize()has been called before accessinginstance.withMobileTimeoutsno longer discards user-suppliedOptionsfields. It now mutates the existing object in-place, only settingreceiveTimeoutwhen the caller has not already provided one.removeAppLocale()now restores the locale that was active atinitialize()time (fromNetworkConfig.defaultHeaders['Accept-Language']) instead of always falling back to'en'.NetworkLocale.clearCustomTranslations([locale])added — removes custom translations for a specific locale, or for all locales when called without an argument.
1.0.0 #
Initial stable release.
Features #
ApiServicesingleton withinitialize(NetworkConfig)entry pointNetworkConfig— configure base URL, timeouts, default headers, SSL, and unauthorized callbackHttpMethodenum —get,post,put,patch,deleteRequestService— unified HTTP request execution with connectivity guard and mobile timeout extensionDownloadRequestService— file download with progress callbackUploadRequestService— multipart file upload with extra fields and progress callbackNetworkLocale— locale-aware error messages; built-in English and Arabic translations covering all standard HTTP status codes and network error types; extensible viaaddTranslations()setAppLocale(locale)— setsAccept-Languageheader and switches error-message locale in one callErrorHandler— convertsDioExceptiontoApiExceptionwith translated messagesApiException— rich exception withstatusCode,apiErrorCode,errorCategory,hasApiErrorCode(), andgetResponseField()ServerFailure/CacheFailure— domain-layerFailurewrappers (Equatable)- Automatic retry on idempotent methods (GET, PUT, DELETE) with exponential back-off (3 retries: 1 s, 2 s, 3 s)
- Connectivity check before every request with a single 600 ms retry for transient states
- Background JSON decoding via
computeisolate - Debug request/response logging via
PrettyDioLogger(debug builds only) - Per-request
baseUrloverride, cancel token, query parameters, and send/receive progress callbacks example/app demonstrating all features against JSONPlaceholder API