fromIdentifier static method
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.
- Parameter
identifier: The raw state identifier received from the platform, such as"connected"or"failed". - Returns: The matching BleConnectionState, or BleConnectionState.unknown when no match is found.
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;
}