tryParse static method

IconData? tryParse(
  1. String source
)

Returns null if source is empty, not valid JSON, or missing codePoint.

Implementation

static IconData? tryParse(String source) {
  if (source.isEmpty) return null;
  try {
    final map = jsonDecode(source);
    if (map is! Map<String, dynamic>) return null;

    final codePoint = map['codePoint'];
    if (codePoint is! int) return null;

    return IconData(
      codePoint,
      fontFamily: map['fontFamily'] as String?,
      fontPackage: map['fontPackage'] as String?,
      matchTextDirection: map['matchTextDirection'] as bool? ?? false,
    );
  } on FormatException {
    return null;
  } on TypeError {
    return null;
  }
}