LanguageInterceptor class
An interceptor that automatically adds language information to HTTP request headers.
This interceptor extracts the user's preferred language from the authentication state and includes it in API requests, enabling the backend to provide localized responses.
Behavior:
- Only adds language header for authenticated users
- Safely handles cases where authentication bloc is not registered
- Skips empty or invalid language codes
Header Added:
X-Language: The user's language code (e.g., "en", "es", "fr")
Use Cases:
- Receiving localized error messages from the API
- Getting content in the user's preferred language
- Analytics and logging based on user language preferences
Example Request:
GET /api/users
X-Language: en-US
Constructors
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
onError(
DioException err, ErrorInterceptorHandler handler) → void -
Called when an exception was occurred during the request.
inherited
-
onRequest(
RequestOptions options, RequestInterceptorHandler handler) → void - Called when the request is about to be sent.
-
onResponse(
Response response, ResponseInterceptorHandler handler) → void -
Called when the response is about to be resolved.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited