fromJson static method

StatsWidgetData fromJson(
  1. Map<String, dynamic> json
)
override

Null when the widget type this build does not know. A server that grows a widget kind must not break a dashboard that renders the rest — the same forward-compatibility rule the schema parser follows.

Implementation

static StatsWidgetData fromJson(Map<String, dynamic> json) {
  final raw = json['stats'];

  return StatsWidgetData(
    heading: json['heading'] is String ? json['heading'] as String : null,
    description: json['description'] is String
        ? json['description'] as String
        : null,
    stats: [
      if (raw is List)
        for (final entry in raw)
          if (entry is Map<String, dynamic>)
            if (StatData.fromJson(entry) case final stat?) stat,
    ],
  );
}