loadRemoteAttachment method

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

Implementation

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

    if (result == null) {
      throw Exception('Failed to load remote attachment: received null result');
    }

    final Map<String, dynamic> attachmentMap = Map<String, dynamic>.from(result);

    if (!attachmentMap.containsKey('filename') || !attachmentMap.containsKey('mimeType') || !attachmentMap.containsKey('data')) {
      throw Exception('Invalid attachment format received from platform');
    }

    if (attachmentMap['data'] is List) {
      attachmentMap['data'] = Uint8List.fromList(List<int>.from(attachmentMap['data']));
    }

    return attachmentMap;
  } catch (e) {
    throw Exception('Failed to load remote attachment: $e');
  }
}