fromJson static method

ReadingView? fromJson(
  1. dynamic value
)

Returns a new ReadingView instance and imports its values from value if it's a Map, null otherwise.

Implementation

// ignore: prefer_constructors_over_static_methods
static ReadingView? fromJson(dynamic value) {
  if (value is Map) {
    final json = value.cast<String, dynamic>();

    // Ensure that the map contains the required keys.
    // Note 1: the values aren't checked for validity beyond being non-null.
    // Note 2: this code is stripped in release mode!
    assert(() {
      requiredKeys.forEach((key) {
        assert(json.containsKey(key), 'Required key "ReadingView[$key]" is missing from JSON.');
        assert(json[key] != null, 'Required key "ReadingView[$key]" has a null value in JSON.');
      });
      return true;
    }());

    return ReadingView(
      account: mapValueOfType<String>(json, r'account'),
      cachedInputTokens: mapValueOfType<int>(json, r'cachedInputTokens'),
      confidence: mapValueOfType<String>(json, r'confidence'),
      costCents: mapValueOfType<int>(json, r'costCents'),
      costLimitCents: mapValueOfType<int>(json, r'costLimitCents'),
      currency: mapValueOfType<String>(json, r'currency'),
      inputTokens: mapValueOfType<int>(json, r'inputTokens'),
      lane: mapValueOfType<String>(json, r'lane'),
      machine: mapValueOfType<String>(json, r'machine'),
      outputTokens: mapValueOfType<int>(json, r'outputTokens'),
      plan: mapValueOfType<String>(json, r'plan'),
      requests: mapValueOfType<int>(json, r'requests'),
      resetsAt: mapValueOfType<String>(json, r'resetsAt'),
      synthetic: mapValueOfType<bool>(json, r'synthetic'),
      totalTokens: mapValueOfType<int>(json, r'totalTokens'),
      usedPct: num.parse('${json[r'usedPct']}'),
      window: mapValueOfType<String>(json, r'window'),
      windowMinutes: mapValueOfType<int>(json, r'windowMinutes'),
      windowStart: mapValueOfType<String>(json, r'windowStart'),
    );
  }
  return null;
}