fromJson static method

StatData? fromJson(
  1. Map<String, dynamic> json
)

Null when label or value is missing — a stat the client cannot render meaningfully is skipped, never shown with a blank number.

Implementation

static StatData? fromJson(Map<String, dynamic> json) {
  final label = json['label'];
  final value = json['value'];
  if (label is! String || label.isEmpty) return null;
  if (value is! String) return null;

  return StatData(
    label: label,
    value: value,
    description: json['description'] is String
        ? json['description'] as String
        : null,
    descriptionIcon: json['descriptionIcon'] is String
        ? json['descriptionIcon'] as String
        : null,
    color: json['color'] is String ? json['color'] as String : null,
    chart: _numbers(json['chart']),
    resourceKey: json['resourceKey'] is String
        ? json['resourceKey'] as String
        : null,
  );
}