fetchMoleculeSvg static method

Future<String> fetchMoleculeSvg(
  1. String smiles
)

Fetches an SVG representation of the molecule from PubChem

Returns the SVG content as a string that can be displayed in web applications

Implementation

static Future<String> fetchMoleculeSvg(String smiles) async {
  if (!isSmilesValid(smiles)) {
    throw ArgumentError('Invalid SMILES string provided');
  }

  final encodedSmiles = Uri.encodeComponent(smiles);
  final url = Uri.parse('$pubchemVisualizationUrl/$encodedSmiles/SVG');

  final response = await http.get(url);
  if (response.statusCode != 200) {
    throw Exception('Failed to fetch molecule SVG: ${response.statusCode}');
  }

  return response.body;
}