fromIdentifier static method

BleConnectionState fromIdentifier(
  1. String? identifier
)

Resolves a BleConnectionState from its String identifier as sent by the native platform.

Matching is case-insensitive. Any value that does not correspond to a known state — including a null argument or an identifier introduced by a newer native layer than this Dart code — resolves to BleConnectionState.unknown rather than throwing. This keeps the method channel handler resilient to unexpected payloads.

Implementation

static BleConnectionState fromIdentifier(String? identifier) {
  if (identifier == null) {
    return BleConnectionState.unknown;
  }

  final String normalized = identifier.toLowerCase();
  for (final BleConnectionState state in BleConnectionState.values) {
    if (state.identifier == normalized) {
      return state;
    }
  }

  return BleConnectionState.unknown;
}