iconData method

  1. @preferInline
IconData? iconData({
  1. required String key,
  2. IconData? defaultValue,
})

Retrieves an IconData value from the JSON map associated with the given key.

If the value associated with the key is already an IconData, it returns that value. If the value is a String, it attempts to resolve it via the Icons lookup table (supports both "add" and "Icons.add" forms). Otherwise, it returns defaultValue.

The parsed or existing IconData is also stored back into the JSON map at the given key.

Returns:

  • An IconData if the value is valid or can be resolved.
  • defaultValue if the value is not valid or cannot be resolved.
  • null if both the value and defaultValue are null.

Implementation

@preferInline
IconData? iconData({
  required String key,
  IconData? defaultValue,
}) {
  final value = _readProp(key, null, false);
  if (value is IconData) return value;
  if (value == null) return defaultValue;

  switch (value) {
    case String():
      return _json[key] = _iconDataStringLookupTable[value]!;
    case Map<String, dynamic>():
      return _json[key] = _iconDataFromMap(value);
    default:
      return defaultValue;
  }
}