BiometricAvailability.fromMap constructor

BiometricAvailability.fromMap(
  1. Map<Object?, Object?> map
)

Parses the native reply defensively; unknown / missing fields fall back to "not available".

Implementation

factory BiometricAvailability.fromMap(Map<Object?, Object?> map) {
  final available = map['available'] == true;
  final rawType = map['type'];
  final rawReason = map['reason'];
  var type = BiometricType.none;
  if (rawType is String) {
    for (final candidate in BiometricType.values) {
      if (candidate.name == rawType) {
        type = candidate;
        break;
      }
    }
  }
  if (available && type == BiometricType.none) type = BiometricType.generic;
  return BiometricAvailability(
    isAvailable: available,
    type: type,
    reason: available ? null : (rawReason is String ? rawReason : null),
  );
}