### bool get hasStringData Source: https://pub.dev/documentation/pretty_dio_logger/latest/pretty_dio_logger/FilterArgs/hasStringData.html A getter that returns true if the data is a string. ```APIDOC ## Property: hasStringData ### Description Returns true if the data is a string. ### Signature `bool get hasStringData` ### Returns - **bool** - Returns true if the data is a string, otherwise false. ``` -------------------------------- ### PrettyDioLogger() Source: https://pub.dev/documentation/pretty_dio_logger/latest/pretty_dio_logger/PrettyDioLogger/PrettyDioLogger.html Initializes a new instance of PrettyDioLogger with configurable logging options. ```APIDOC ## PrettyDioLogger() ### Description Initializes the PrettyDioLogger interceptor with specific configuration flags for request and response logging. ### Parameters - **request** (bool) - Optional - Whether to log request information. Defaults to true. - **requestHeader** (bool) - Optional - Whether to log request headers. Defaults to false. - **requestBody** (bool) - Optional - Whether to log request bodies. Defaults to false. - **responseHeader** (bool) - Optional - Whether to log response headers. Defaults to false. - **responseBody** (bool) - Optional - Whether to log response bodies. Defaults to true. - **error** (bool) - Optional - Whether to log error information. Defaults to true. - **maxWidth** (int) - Optional - The maximum width of the log output. Defaults to 90. - **compact** (bool) - Optional - Whether to use a compact log format. Defaults to true. - **logPrint** (Function) - Optional - A custom function to handle log output. Defaults to print. - **filter** (Function) - Optional - A filter function to determine if a request should be logged. - **enabled** (bool) - Optional - Whether the logger is enabled. Defaults to true. ``` -------------------------------- ### Initialize PrettyDioLogger Source: https://pub.dev/documentation/pretty_dio_logger/latest/pretty_dio_logger/PrettyDioLogger/PrettyDioLogger.html The constructor accepts various boolean flags to toggle logging components and configuration for output formatting. ```dart PrettyDioLogger({ this.request = true, this.requestHeader = false, this.requestBody = false, this.responseHeader = false, this.responseBody = true, this.error = true, this.maxWidth = 90, this.compact = true, this.logPrint = print, this.filter, this.enabled = true, }); ``` -------------------------------- ### void onResponse(Response response, ResponseInterceptorHandler handler) Source: https://pub.dev/documentation/pretty_dio_logger/latest/pretty_dio_logger/PrettyDioLogger/onResponse.html This method is called when the response is about to be resolved. It logs the response header, headers, and body if enabled, and proceeds with the response handling. ```APIDOC ## void onResponse(Response response, ResponseInterceptorHandler handler) ### Description Called when the response is about to be resolved. It checks if logging is enabled and if the response passes the filter, then logs the response details before calling the next handler. ### Parameters - **response** (Response) - The response object received from the request. - **handler** (ResponseInterceptorHandler) - The handler used to continue the response chain. ``` -------------------------------- ### Initialize FilterArgs Source: https://pub.dev/documentation/pretty_dio_logger/latest/pretty_dio_logger/FilterArgs/FilterArgs.html Use the const constructor to create a new instance of FilterArgs with response status and data. ```dart const FilterArgs(this.isResponse, this.data); ``` -------------------------------- ### Implementation of onResponse in PrettyDioLogger Source: https://pub.dev/documentation/pretty_dio_logger/latest/pretty_dio_logger/PrettyDioLogger/onResponse.html This method processes the response, calculates the request duration, and logs headers and body content if enabled. ```dart @override void onResponse(Response response, ResponseInterceptorHandler handler) { if (!enabled || (filter != null && !filter!( response.requestOptions, FilterArgs(true, response.data)))) { handler.next(response); return; } final triggerTime = response.requestOptions.extra[_timeStampKey]; int diff = 0; if (triggerTime is int) { diff = DateTime.timestamp().millisecondsSinceEpoch - triggerTime; } _printResponseHeader(response, diff); if (responseHeader) { final responseHeaders = {}; response.headers .forEach((k, list) => responseHeaders[k] = list.toString()); _printMapAsTable(responseHeaders, header: 'Headers'); } if (responseBody) { logPrint('╔ Body'); logPrint('║'); _printResponse(response); logPrint('║'); _printLine('╚'); } handler.next(response); } ``` -------------------------------- ### Integrating and Customizing PrettyDioLogger Source: https://pub.dev/documentation/pretty_dio_logger/latest/index.html Add the interceptor to your Dio instance. Use the constructor parameters to toggle logging details and the filter function to exclude specific requests or responses. ```dart Dio dio = Dio(); dio.interceptors.add(PrettyDioLogger()); // customization dio.interceptors.add(PrettyDioLogger( requestHeader: true, requestBody: true, responseBody: true, responseHeader: false, error: true, compact: true, maxWidth: 90, enabled: kDebugMode, filter: (options, args){ // don't print requests with uris containing '/posts' if(options.path.contains('/posts')){ return false; } // don't print responses with unit8 list data return !args.isResponse || !args.hasUint8ListData; } ) ); ``` -------------------------------- ### Implement logPrint property Source: https://pub.dev/documentation/pretty_dio_logger/latest/pretty_dio_logger/PrettyDioLogger/logPrint.html Defines the signature for the log printing function used by the logger. ```dart final void Function(Object object) logPrint; ``` -------------------------------- ### void onRequest(RequestOptions options, RequestInterceptorHandler handler) Source: https://pub.dev/documentation/pretty_dio_logger/latest/pretty_dio_logger/PrettyDioLogger/onRequest.html This method is called by the Dio interceptor chain when a request is initiated. It logs request details such as headers, query parameters, and body content if the logger is enabled and the request passes the filter criteria. ```APIDOC ## void onRequest(RequestOptions options, RequestInterceptorHandler handler) ### Description Intercepts the outgoing request to log its details. It attaches a timestamp to the request extras and processes logging based on the `request`, `requestHeader`, and `requestBody` configuration flags. ### Parameters - **options** (RequestOptions) - The configuration options for the current request. - **handler** (RequestInterceptorHandler) - The handler used to continue the request chain via `handler.next(options)`. ``` -------------------------------- ### Implementation of maxWidth Source: https://pub.dev/documentation/pretty_dio_logger/latest/pretty_dio_logger/PrettyDioLogger/maxWidth.html Defines the integer property used to control the width of log prints. ```dart final int maxWidth; ``` -------------------------------- ### Implement onRequest method Source: https://pub.dev/documentation/pretty_dio_logger/latest/pretty_dio_logger/PrettyDioLogger/onRequest.html This method intercepts outgoing requests to log details like headers, query parameters, and body content if enabled. ```dart @override void onRequest(RequestOptions options, RequestInterceptorHandler handler) { final extra = Map.of(options.extra); options.extra[_timeStampKey] = DateTime.timestamp().millisecondsSinceEpoch; if (!enabled || (filter != null && !filter!(options, FilterArgs(false, options.data)))) { handler.next(options); return; } if (request) { _printRequestHeader(options); } if (requestHeader) { _printMapAsTable(options.queryParameters, header: 'Query Parameters'); final requestHeaders = {}; requestHeaders.addAll(options.headers); if (options.contentType != null) { requestHeaders['contentType'] = options.contentType?.toString(); } requestHeaders['responseType'] = options.responseType.toString(); requestHeaders['followRedirects'] = options.followRedirects; if (options.connectTimeout != null) { requestHeaders['connectTimeout'] = options.connectTimeout?.toString(); } if (options.receiveTimeout != null) { requestHeaders['receiveTimeout'] = options.receiveTimeout?.toString(); } _printMapAsTable(requestHeaders, header: 'Headers'); _printMapAsTable(extra, header: 'Extras'); } if (requestBody && options.method != 'GET') { final dynamic data = options.data; if (data != null) { if (data is Map) _printMapAsTable(options.data as Map?, header: 'Body'); if (data is FormData) { final formDataMap = {} ..addEntries(data.fields) ..addEntries(data.files); _printMapAsTable(formDataMap, header: 'Form data | ${data.boundary}'); } else { _printBlock(data.toString()); } } } handler.next(options); } ``` -------------------------------- ### FilterArgs Constructor Source: https://pub.dev/documentation/pretty_dio_logger/latest/pretty_dio_logger/FilterArgs-class.html Initializes a new instance of FilterArgs to hold data for either a request or a response. ```APIDOC ## FilterArgs(bool isResponse, dynamic data) ### Description Creates a new FilterArgs instance. Set `isResponse` to true if the data originates from a response, or false if it originates from request options. ### Parameters - **isResponse** (bool) - Required - Indicates if the data is from a response (true) or a request (false). - **data** (dynamic) - Required - The actual data payload from the request or response. ``` -------------------------------- ### Define tabStep constant Source: https://pub.dev/documentation/pretty_dio_logger/latest/pretty_dio_logger/PrettyDioLogger/tabStep-constant.html The tabStep constant represents a single tab length, defined as four spaces. ```dart static const String tabStep = ' '; ``` -------------------------------- ### Implementation of request property Source: https://pub.dev/documentation/pretty_dio_logger/latest/pretty_dio_logger/PrettyDioLogger/request.html Defines the final boolean property used to toggle request logging. ```dart final bool request; ``` -------------------------------- ### Implementation of kInitialTab Source: https://pub.dev/documentation/pretty_dio_logger/latest/pretty_dio_logger/PrettyDioLogger/kInitialTab-constant.html The constant is defined as a static integer with a default value of 1. ```dart static const int kInitialTab = 1; ``` -------------------------------- ### Define responseHeader property Source: https://pub.dev/documentation/pretty_dio_logger/latest/pretty_dio_logger/PrettyDioLogger/responseHeader.html The property is defined as a final boolean value. ```dart final bool responseHeader; ``` -------------------------------- ### FilterArgs(bool isResponse, dynamic data) Source: https://pub.dev/documentation/pretty_dio_logger/latest/pretty_dio_logger/FilterArgs/FilterArgs.html The constructor for the FilterArgs class, which initializes the response status and associated data. ```APIDOC ## FilterArgs Constructor ### Description Creates a new instance of FilterArgs with the specified response status and data. ### Signature `const FilterArgs(bool isResponse, dynamic data)` ### Parameters - **isResponse** (bool) - Required - Indicates whether the filter applies to a response. - **data** (dynamic) - Required - The data associated with the filter. ``` -------------------------------- ### hasUint8ListData Source: https://pub.dev/documentation/pretty_dio_logger/latest/pretty_dio_logger/FilterArgs/hasUint8ListData.html A boolean property that returns true if the data is a Uint8List. ```APIDOC ## hasUint8ListData ### Description Returns true if the data is a Uint8List. ### Signature `bool get hasUint8ListData` ### Implementation ```dart bool get hasUint8ListData => data is Uint8List; ``` ``` -------------------------------- ### Implement onError method Source: https://pub.dev/documentation/pretty_dio_logger/latest/pretty_dio_logger/PrettyDioLogger/onError.html Overrides the default onError handler to log DioException details based on configured filters and error settings. ```dart @override void onError(DioException err, ErrorInterceptorHandler handler) { if (!enabled || (filter != null && !filter!( err.requestOptions, FilterArgs(true, err.response?.data)))) { handler.next(err); return; } final triggerTime = err.requestOptions.extra[_timeStampKey]; if (error) { if (err.type == DioExceptionType.badResponse) { final uri = err.response?.requestOptions.uri; int diff = 0; if (triggerTime is int) { diff = DateTime.timestamp().millisecondsSinceEpoch - triggerTime; } _printBoxed( header: 'DioError ║ Status: ${err.response?.statusCode} ${err.response?.statusMessage} ║ Time: $diff ms', text: uri.toString()); if (err.response != null && err.response?.data != null) { logPrint('╔ ${err.type.toString()}'); _printResponse(err.response!); } _printLine('╚'); logPrint(''); } else { _printBoxed(header: 'DioError ║ ${err.type}', text: err.message); } } handler.next(err); } ``` -------------------------------- ### Implementation of hasUint8ListData Source: https://pub.dev/documentation/pretty_dio_logger/latest/pretty_dio_logger/FilterArgs/hasUint8ListData.html This property returns true if the data is an instance of Uint8List. ```dart bool get hasUint8ListData => data is Uint8List; ``` -------------------------------- ### Implementation of the error property Source: https://pub.dev/documentation/pretty_dio_logger/latest/pretty_dio_logger/PrettyDioLogger/error.html Defines the error boolean property used for logging configuration. ```dart final bool error; ``` -------------------------------- ### maxWidth property Source: https://pub.dev/documentation/pretty_dio_logger/latest/pretty_dio_logger/PrettyDioLogger/maxWidth.html The maxWidth property is an integer that determines the maximum width size per logPrint operation. ```APIDOC ## Property: maxWidth ### Description Defines the maximum width size for log output generated by the PrettyDioLogger. ### Type int ### Usage This property is used to constrain the width of the logs printed to the console. ``` -------------------------------- ### PrettyDioLogger.responseBody Source: https://pub.dev/documentation/pretty_dio_logger/latest/pretty_dio_logger/PrettyDioLogger/responseBody.html A boolean property that controls the logging of the response body in PrettyDioLogger. ```APIDOC ## Property: responseBody ### Description Determines whether the `Response.data` should be printed to the console during logging. ### Type `bool` ### Usage Set to `true` to enable printing of the response body, or `false` to disable it. ``` -------------------------------- ### responseHeader property Source: https://pub.dev/documentation/pretty_dio_logger/latest/pretty_dio_logger/PrettyDioLogger/responseHeader.html The responseHeader property is a final boolean field used to toggle the logging of Response headers. ```APIDOC ## responseHeader ### Description A boolean property that controls whether the `Response.headers` are included in the PrettyDioLogger output. ### Type `bool` (final) ### Usage Set this property to `true` to enable printing of response headers, or `false` to disable it. ``` -------------------------------- ### Implementation of isResponse property Source: https://pub.dev/documentation/pretty_dio_logger/latest/pretty_dio_logger/FilterArgs/isResponse.html The property is defined as a final boolean field. ```dart final bool isResponse; ``` -------------------------------- ### void onError(DioException err, ErrorInterceptorHandler handler) Source: https://pub.dev/documentation/pretty_dio_logger/latest/pretty_dio_logger/PrettyDioLogger/onError.html This method is called by the Dio client when an exception occurs during a request. It logs the error details if logging is enabled and passes the error to the next interceptor. ```APIDOC ## void onError(DioException err, ErrorInterceptorHandler handler) ### Description Called when an exception occurs during a request. It checks if logging is enabled and if the error passes the defined filter before printing formatted error logs to the console. ### Parameters - **err** (DioException) - Required - The exception object containing details about the failed request. - **handler** (ErrorInterceptorHandler) - Required - The handler used to pass the error to the next interceptor in the chain. ``` -------------------------------- ### enabled property Source: https://pub.dev/documentation/pretty_dio_logger/latest/pretty_dio_logger/PrettyDioLogger/enabled.html The enabled property is a final boolean value that determines whether the logger should print output. When set to true, logs are enabled; when false, logging is suppressed. ```APIDOC ## Property: enabled ### Description A boolean flag that controls whether the PrettyDioLogger prints logs. This property is final and is typically set during the initialization of the logger. ### Type `bool` ### Usage ```dart final logger = PrettyDioLogger( enabled: true, // Set to false to disable logging ); ``` ``` -------------------------------- ### Define chunkSize constant Source: https://pub.dev/documentation/pretty_dio_logger/latest/pretty_dio_logger/PrettyDioLogger/chunkSize-constant.html The chunkSize constant is set to 20, determining the split size for Uint8List data. ```dart static const int chunkSize = 20; ``` -------------------------------- ### filter property Source: https://pub.dev/documentation/pretty_dio_logger/latest/pretty_dio_logger/PrettyDioLogger/filter.html A callback function that determines if a request or response should be logged. It takes RequestOptions and FilterArgs as parameters and returns a boolean. ```APIDOC ## filter property ### Description A callback function used to filter log output. If provided, the logger will only output logs when this function returns true. ### Signature `bool Function(RequestOptions options, FilterArgs args)? filter` ### Parameters - **options** (RequestOptions) - The request options associated with the current log event. - **args** (FilterArgs) - Additional arguments provided for filtering logic. ``` -------------------------------- ### logPrint property Source: https://pub.dev/documentation/pretty_dio_logger/latest/pretty_dio_logger/PrettyDioLogger/logPrint.html The logPrint property defines the function used to output log messages. It defaults to printing to the console, but can be overridden to use debugPrint or custom file logging. ```APIDOC ## logPrint ### Description A callback function used to print log messages. By default, it logs to the console. Users can provide a custom function to redirect logs to `debugPrint` or a file. ### Signature `void Function(Object object) logPrint` ### Usage Assign a function to this property to handle log output: ```dart PrettyDioLogger( logPrint: (object) => debugPrint(object.toString()), ); ``` ``` -------------------------------- ### FilterArgs Properties Source: https://pub.dev/documentation/pretty_dio_logger/latest/pretty_dio_logger/FilterArgs-class.html Properties available on the FilterArgs instance to inspect the data type and origin. ```APIDOC ## Properties - **data** (dynamic) - The raw data payload. - **isResponse** (bool) - Indicates if the filter is for a request or response. - **hasJsonData** (bool) - Returns true if the data is JSON. - **hasListData** (bool) - Returns true if the data is a list. - **hasMapData** (bool) - Returns true if the data is a map. - **hasStringData** (bool) - Returns true if the data is a string. - **hasUint8ListData** (bool) - Returns true if the data is a Uint8List. ``` -------------------------------- ### Define the data property Source: https://pub.dev/documentation/pretty_dio_logger/latest/pretty_dio_logger/FilterArgs/data.html The data property is defined as a final dynamic field. ```dart final dynamic data; ``` -------------------------------- ### Implementation of hasStringData Source: https://pub.dev/documentation/pretty_dio_logger/latest/pretty_dio_logger/FilterArgs/hasStringData.html The getter checks the type of the data property. ```dart bool get hasStringData => data is String; ``` -------------------------------- ### Implementation of hasListData Source: https://pub.dev/documentation/pretty_dio_logger/latest/pretty_dio_logger/FilterArgs/hasListData.html The property returns true if the data is a List. ```dart bool get hasListData => data is List; ``` -------------------------------- ### Implementation of hasJsonData Source: https://pub.dev/documentation/pretty_dio_logger/latest/pretty_dio_logger/FilterArgs/hasJsonData.html This getter checks if the data is either a map or a list to determine if it is JSON. ```dart bool get hasJsonData => hasMapData || hasListData; ``` -------------------------------- ### Define responseBody property Source: https://pub.dev/documentation/pretty_dio_logger/latest/pretty_dio_logger/PrettyDioLogger/responseBody.html Declaration of the responseBody boolean property used to toggle response data logging. ```dart final bool responseBody; ``` -------------------------------- ### requestHeader property Source: https://pub.dev/documentation/pretty_dio_logger/latest/pretty_dio_logger/PrettyDioLogger/requestHeader.html The requestHeader property is a boolean flag that determines whether the interceptor should print the request headers (Options.headers) to the console. ```APIDOC ## requestHeader ### Description A boolean property that controls whether the request headers are included in the log output. ### Type bool ### Usage Set to true to enable printing of `Options.headers` in the request logs. ``` -------------------------------- ### Define requestBody property Source: https://pub.dev/documentation/pretty_dio_logger/latest/pretty_dio_logger/PrettyDioLogger/requestBody.html Declaration of the requestBody boolean property within the PrettyDioLogger configuration. ```dart final bool requestBody; ``` -------------------------------- ### Define requestHeader property Source: https://pub.dev/documentation/pretty_dio_logger/latest/pretty_dio_logger/PrettyDioLogger/requestHeader.html The requestHeader property is defined as a final boolean value. ```dart final bool requestHeader; ``` -------------------------------- ### Define enabled property Source: https://pub.dev/documentation/pretty_dio_logger/latest/pretty_dio_logger/PrettyDioLogger/enabled.html The enabled property is defined as a final boolean value. ```dart final bool enabled; ``` -------------------------------- ### Implementation of hasMapData Source: https://pub.dev/documentation/pretty_dio_logger/latest/pretty_dio_logger/FilterArgs/hasMapData.html Returns true if the data is a map. ```dart bool get hasMapData => data is Map; ``` -------------------------------- ### PrettyDioLogger filter property definition Source: https://pub.dev/documentation/pretty_dio_logger/latest/pretty_dio_logger/PrettyDioLogger/filter.html The filter property is a function that takes RequestOptions and FilterArgs as arguments and returns a boolean. ```dart final bool Function(RequestOptions options, FilterArgs args)? filter; ``` -------------------------------- ### Define compact property Source: https://pub.dev/documentation/pretty_dio_logger/latest/pretty_dio_logger/PrettyDioLogger/compact.html The compact property is defined as a final boolean value. ```dart final bool compact; ``` -------------------------------- ### hasJsonData Source: https://pub.dev/documentation/pretty_dio_logger/latest/pretty_dio_logger/FilterArgs/hasJsonData.html A boolean property that returns true if the data is identified as JSON data (either a Map or a List). ```APIDOC ## hasJsonData ### Description Returns a boolean value indicating whether the data is JSON data. It evaluates to true if the data is either map data or list data. ### Signature bool get hasJsonData ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.