fromMap static method
Implementation
static APICredential? fromMap(Map<String, dynamic>? map,
{bool requiresUsernameAndPassword = false}) {
if (map == null) {
if (!requiresUsernameAndPassword) {
return null;
}
map = {};
}
var username = map.getAsString('username', ignoreCase: true) ??
map.getAsString('user', ignoreCase: true)?.trim();
var password = map.getAsString('password', ignoreCase: true) ??
map.getAsString('pass', ignoreCase: true)?.trim();
if (requiresUsernameAndPassword) {
if (password == null || password.isEmpty) {
throw ArgumentError("Can't define `password` from passed `map`.");
}
if (username == null || username.isEmpty) {
throw ArgumentError("Can't define `username` from passed `map`.");
}
} else {
if (username == null) return null;
}
return APICredential(username, passwordHash: password);
}