MediaApiService class
- Inheritance
-
- Object
- DioApiService
- NyApiService
- MediaApiService
Constructors
Properties
- activeRequestCount → int
-
Get the count of active (non-cancelled) requests.
no setterinherited
- baseOptions ↔ BaseOptions?
-
Base options for the request
getter/setter pairinherited
- baseUrl → String
-
Base URL for the request
finalinherited
- checkConnectivityBeforeRequest ↔ bool
-
Whether to check connectivity before making a request.
If true and the device is offline, the request will fail immediately
with a
DioExceptionType.connectionErrorinstead of waiting for timeout.getter/setter pairinherited -
decoders
→ Map<
Type, dynamic> ? -
Map decoders to modelDecoders
finalinherited
- dio → Dio
-
Get the Dio instance for making custom requests
no setterinherited
- hashCode → int
-
The hash code for this object.
no setterinherited
-
interceptors
→ Map<
Type, Interceptor> -
Default interceptors
no setteroverride
- networkLogger ↔ NetworkLogger?
-
Network logger instance
getter/setter pairinherited
- retry ↔ int
-
how many times should the request retry
getter/setter pairinherited
- retryDelay ↔ Duration
-
how long should the request wait before retrying
getter/setter pairinherited
- retryIf ↔ bool Function(DioException dioException)?
-
should the request retry if the
retryIfcallback returns truegetter/setter pairinherited - runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- shouldSetAuthHeaders ↔ bool
-
should the request retry if the
retryIfcallback returns truegetter/setter pairinherited - useHttpOnResponse → bool
-
Use HTTP on response
finalinherited
- useInterceptors → bool
-
Use interceptors
no setterinherited
- useNetworkLogger ↔ bool?
-
Whether to use the network logger interceptor
getter/setter pairinherited
Methods
-
cancelAllRequests(
[String? reason]) → void -
Cancel all active requests that were created with
createCancelToken. Optionally provide areasonthat will be included in the cancellation error.inherited -
clearAllCache(
) → Future< void> -
Clear all API cache entries.
inherited
-
clearCache(
String cacheKey) → Future< void> -
Clear a specific cache entry.
inherited
-
compressImage(
XFile file, {ImageCompressionOptions options = const ImageCompressionOptions()}) → Future< Uint8List> -
Compress an image using smart quality tiers + optional downscale.
Files at or below
options.skipBelowBytesare returned unchanged. -
compressWithGzip(
List< int> data) → Future<List< int> > - Compress data using GZip in a background isolate to avoid jank.
-
createCancelToken(
) → CancelToken -
Create a managed
CancelTokenthat is tracked by this service. Use this to create tokens that can be cancelled withcancelAllRequests.inherited -
createEnhancedResponse<
T> (Response response) → NyResponse< T> -
Creates an enhanced API response from a Dio response and type
This is a convenience method for creating NyResponse objects
inherited
-
delete<
T> (String url, {Object? data, Options? options, CancelToken? cancelToken}) → Future< T?> -
Make a DELETE request
inherited
-
deleteImage(
dynamic item, {required ApiRequest apiRequest}) → Future - Delete an image
-
download(
String url, {required String savePath, ProgressCallback? onProgress, bool deleteOnError = true, CancelToken? cancelToken, Map< String, dynamic> ? queryParameters, Options? options}) → Future<Response> -
Download a file from the given URL to a local path.
inherited
-
error(
DioException dioException) → void -
Handle the
DioExceptionresponse if there is an issue.inherited -
extractData<
T> (NyResponse< T> enhancedResponse) → T? -
Convenience method to extract just the data from an enhanced response
This helps with migration from the old handleResponse method
inherited
-
get<
T> (String url, {Object? data, Map< String, String> ? queryParameters, Options? options, CancelToken? cancelToken, ProgressCallback? onReceiveProgress}) → Future<T?> -
Make a GET request
inherited
-
getDataIfSuccessful<
T> (NyResponse< T> enhancedResponse) → T? -
Convenience method to check if an enhanced response is successful
and return the data or null if not successful
inherited
-
handleResponse<
T> (Response response, {dynamic handleSuccess(NyResponse< T> response)?, dynamic handleFailure(NyResponse<T> response)?}) → NyResponse<T> -
Handles an API network response from
Dio. Returns a comprehensive NyResponse object containing the original Dio Response, morphed data, and useful utilities.inherited -
head(
String url, {Object? data, Map< String, String> ? queryParameters, Options? options, CancelToken? cancelToken}) → Future<Response> -
Make a HEAD request to check resource existence or get headers
inherited
-
init(
) → void -
Initialize class
inherited
-
network<
T> ({required dynamic request(Dio api), dynamic handleSuccess(NyResponse< T> response)?, dynamic handleFailure(NyResponse<T> response)?, String? bearerToken, String? baseUrl, bool useUndefinedResponse = true, bool shouldRetry = true, bool? shouldSetAuthHeaders, int? retry, Duration? retryDelay, bool retryIf(DioException dioException)?, Duration? connectionTimeout, Duration? receiveTimeout, Duration? sendTimeout, Duration? cacheDuration, String? cacheKey, CachePolicy? cachePolicy, bool? checkConnectivity, Map<String, dynamic> ? headers}) → Future<T?> -
Networking class to handle API requests
Use the
requestcallback to call an APIhandleSuccessoverrides the response on a successful status codehandleFailureoverrides the response on a failureinherited -
networkResponse<
T> ({required dynamic request(Dio api), dynamic handleSuccess(NyResponse< T> response)?, dynamic handleFailure(NyResponse<T> response)?, String? bearerToken, String? baseUrl, bool useUndefinedResponse = true, bool shouldRetry = true, bool? shouldSetAuthHeaders, int? retry, Duration? retryDelay, bool retryIf(DioException dioException)?, Duration? connectionTimeout, Duration? receiveTimeout, Duration? sendTimeout, Duration? cacheDuration, String? cacheKey, CachePolicy? cachePolicy, bool? checkConnectivity, Map<String, dynamic> ? headers}) → Future<NyResponse< T> > -
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
onError(
dynamic onError(DioException dioException)) → void -
Set the
onErrorcallback for the requestinherited -
onSuccess(
dynamic onSuccess(Response response, dynamic data)) → void -
Set the
onSuccesscallback for the requestinherited -
onUndefinedResponse(
dynamic data, Response response) → void -
Handle the undefined response's for HTTP requests.
The
dataparameter contains what was returned from your decoder.inherited -
patch<
T> (String url, {Object? data, Options? options, CancelToken? cancelToken, ProgressCallback? onSendProgress, ProgressCallback? onReceiveProgress}) → Future< T?> -
Make a PATCH request
inherited
-
post<
T> (String url, {Object? data, Options? options, CancelToken? cancelToken, ProgressCallback? onSendProgress, ProgressCallback? onReceiveProgress}) → Future< T?> -
Make a POST request
inherited
-
put<
T> (String url, {Object? data, Options? options, CancelToken? cancelToken, ProgressCallback? onSendProgress, ProgressCallback? onReceiveProgress}) → Future< T?> -
Make a PUT request
inherited
-
refreshToken(
Dio dio) → Future< void> -
Perform a
Diorequest to update the users auth token. This method is called whenshouldRefreshTokenreturns true. You can override this method to perform your own request. Thedioparameter is a new instance ofDio. You can use this to perform a request without affecting the originalDioinstance.inherited -
removeCancelToken(
CancelToken token) → void -
Remove a specific cancel token from the tracked list.
Call this when a request completes to clean up the token.
inherited
-
setAuthHeaders(
RequestHeaders headers) → Future< RequestHeaders> -
Set the auth headers for the request.
The
headersparameter contains the current headers.inherited -
setBaseUrl(
String baseUrl) → void -
Set a
baseUrlfor the request.inherited -
setBearerToken(
String bearerToken) → void -
Set a bearer token
headersto the baseOptions variable.inherited -
setCache(
Duration? duration, String cacheKey) → void -
Set the cache for the request.
inherited
-
setCheckConnectivityBeforeRequest(
bool check) → void -
Set whether to check connectivity before making requests.
When enabled, requests will fail immediately if the device is offline.
inherited
-
setConnectTimeout(
Duration duration) → void -
Set the
connectTimeoutfor the request.inherited -
setContentType(
String contentType) → void -
Set the
contentTypefor the request.inherited -
setHeaders(
Map< String, dynamic> headers) → void -
Set new
headersto the baseOptions variable.inherited -
setMainImage(
{required ApiRequest apiRequest}) → Future - Set an image as the main image
-
setMethod(
String method) → void -
Set the
methodfor the request.inherited -
setOptions(
BaseOptions baseOptions) → void -
Set the
baseOptionsfor the request.inherited -
setPagination(
int page, {String? paramPage, String? paramPerPage, String? perPage}) → void -
Apply a pagination query to the HTTP request
inherited
-
setReceiveTimeout(
Duration duration) → void -
Set the
receiveTimeoutfor the request.inherited -
setRetry(
int retry) → void -
Set how many times the request should
retryif it fails.inherited -
setRetryDelay(
Duration retryDelay) → void -
Set the Duration how long the request should wait before retrying.
inherited
-
setRetryIf(
bool retryIf(DioException dioException)) → void -
Set if the request should
shouldRetryif theretryIfreturns true.inherited -
setSendTimeout(
Duration duration) → void -
Set the
sendTimeoutfor the request.inherited -
setShouldSetAuthHeaders(
bool shouldSetAuthHeaders) → void -
Set if the request should
shouldSetAuthHeadersif theshouldRefreshTokenreturns true.inherited -
shouldRefreshToken(
) → Future< bool> -
Check if the users auth token should be refreshed.
This method is called before every request.
You can override this method to perform your own checks.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
-
upload<
T> (String url, {required String filePath, String fieldName = 'file', Map< String, dynamic> ? additionalFields, ProgressCallback? onProgress, String? fileName, String? contentType, CancelToken? cancelToken}) → Future<T?> -
Upload a file using multipart/form-data.
inherited
-
uploadAudio(
PickedFileInfo audio, {required ApiRequest apiRequest}) → Future - Upload a single audio file.
-
uploadFile(
PickedFileInfo file, {required ApiRequest apiRequest}) → Future - Upload a single arbitrary file.
-
uploadImage(
XFile image, {required ApiRequest apiRequest}) → Future - Upload a single image
-
uploadImages(
List< XFile> images, {required ApiRequest apiRequest}) → Future - Upload multiple images in a single multipart request (parallel form fields).
-
uploadImagesGzip(
List< XFile> images, {required ApiRequest apiRequest, void onSendProgress(int sent, int total)?, ImageCompressionOptions? compressionOptions}) → Future -
Upload multiple images with smart compression + gzip.
Sets
Content-Encoding: gzipheader. Server must support gzipped multipart. -
uploadImagesSequential(
List< XFile> images, {required ApiRequest apiRequest}) → Future - Upload multiple images sequentially — one image per request. Use when the server can only accept a single image per call.
-
uploadImagesWithMode(
List< XFile> images, {required ApiRequest apiRequest, required UploadMode mode, ImageCompressionOptions? compressionOptions, void onSendProgress(int sent, int total)?}) → Future -
Unified entry point that dispatches to the right upload method based
on
mode. Used byGridImagePickerand exposed for advanced consumers. -
uploadMultiple<
T> (String url, {required Map< String, String> files, Map<String, dynamic> ? additionalFields, ProgressCallback? onProgress, CancelToken? cancelToken}) → Future<T?> -
Upload multiple files using multipart/form-data.
inherited
-
uploadVideo(
PickedFileInfo video, {required ApiRequest apiRequest}) → Future - Upload a single video.
-
uploadVideos(
List< PickedFileInfo> videos, {required ApiRequest apiRequest, UploadMode mode = UploadMode.standard}) → Future - Upload multiple videos. UploadMode.gzip is rejected — gzip on encoded video is wasted CPU.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited