getUsbConnectionStatus method

  1. @override
Future<Map<String, dynamic>> getUsbConnectionStatus()
override

Get USB connection status details

Implementation

@override
Future<Map<String, dynamic>> getUsbConnectionStatus() async {
  try {
    final result = await methodChannel.invokeMethod<dynamic>(
      'getUsbConnectionStatus',
    );

    debugPrint('USB Connection Status Result Type: ${result.runtimeType}');
    debugPrint('USB Connection Status Result: $result');

    // Handle type conversion from platform-specific implementations
    if (result is Map) {
      // Convert the map to the expected type with proper type safety
      final Map<String, dynamic> convertedMap = <String, dynamic>{};
      result.forEach((key, value) {
        final String stringKey = key is String ? key : key.toString();
        convertedMap[stringKey] = value;
      });

      return convertedMap;
    }

    debugPrint('Result is not a Map, returning default values');
    return _getDefaultUsbStatus(
      'Invalid response type: ${result.runtimeType}',
    );
  } catch (e) {
    debugPrint('Error in getUsbConnectionStatus: $e');
    return _getDefaultUsbStatus('Exception: $e');
  }
}