AuthResponse class
This class represents the response entity of the authentication API in the Duolingo API.
The error field is set to an object only if an authentication error has occurred, and null if there is no authentication error. It should be used in the caller's processing, as it provides hasError and hasNotError methods to safely check for the presence of authentication errors.
Example:
void main() async {
final duolingo = Duolingo.instance;
final authResponse = await duolingo.authenticate(
username: 'test_username',
password: 'test_password',
);
if (authResponse.status.isNotOk) {
authResponse.status.reasonPhrase;
authResponse.headers;
return;
}
if (authResponse.hasError) {
final authError = authResponse.error!;
print(authError.code);
print(authError.reason);
authError.isInvalidUser;
authError.isInvalidPassword;
return;
}
}
Constructors
-
AuthResponse.from({required int statusCode, required String reasonPhrase, required Map<
String, String> headers, required String username, required String userId, required AuthError? error}) - Returns the new instance of AuthResponse based on arguments.
Properties
- error → AuthError?
-
The error object
final
- hasError → bool
-
Returns true if the response has error, otherwise false.
no setter
- hashCode → int
-
The hash code for this object.
no setteroverride
- hasNotError → bool
-
Returns true if the response has not error, otherwise false.
no setter
-
headers
→ Map<
String, String> -
The http headers
finalinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- status → Status
-
The http status
finalinherited
- userId → String
-
The user id
final
- username → String
-
The username
final
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
override