getSafetyData static method
Retrieves safety data for a chemical compound by name or identifier.
Parameters:
chemical: The name, CAS number, or other identifier for the chemicaluseCached: Whether to use cached data if available (default: true)
Returns a map containing safety information including:
- GHS classifications
- Hazard statements (H-codes)
- Precautionary statements (P-codes)
- Signal word (Danger/Warning)
- Pictograms
Implementation
static Future<Map<String, dynamic>> getSafetyData(String chemical, {bool useCached = true}) async {
// Check cache first if enabled
if (useCached && _cache.containsKey(chemical)) {
return Map.from(_cache[chemical]!);
}
try {
// Step 1: Search for the compound to get its CID
final cid = await _getCompoundCID(chemical);
if (cid == null) {
return {'error': 'Compound not found'};
}
// Step 2: Get safety data using the CID
final safetyData = await _fetchSafetyData(cid);
// Cache the result
_cache[chemical] = Map.from(safetyData);
return safetyData;
} catch (e) {
return {'error': 'Failed to retrieve safety data: $e'};
}
}