prepareMessage method

  1. @override
Future<Uint8List?> prepareMessage(
  1. BuildContext? context
)
override

Prepares the message by fetching the SVG data from the network.

Implementation

@override
Future<Uint8List?> prepareMessage(BuildContext? context) async {
  final http.Client client = _httpClient ?? http.Client();
  try {
    final response = await client.get(Uri.parse(url), headers: headers);
    if (response.statusCode == 200) {
      return response.bodyBytes;
    } else {
      // Handle non-200 responses appropriately
      if (kDebugMode) {
        print('Failed to load SVG from $url: ${response.statusCode}');
      }
      return null;
    }
  } catch (e) {
    // Handle network errors, log them
    if (kDebugMode) {
      print('Error loading SVG from $url: $e');
    }
    return null;
  } finally {
    if (_httpClient == null) {
      client.close(); // Close the client only if it was created internally
    }
  }
}