fromJson static method

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

Implementation

static FFill fromJson(final Map<String, dynamic> json) {
  if (json['t'] == 'json') {
    return FFill(
      type: FFillType.json,
      jsonGetAttribute: JsonGetAttribute.fromJson(json['json_get_attr']),
    );
  }
  if (json['varID'] != null || json['t'] == 'v') {
    return FFill(
      variableID: json['varID'],
      type: FFillType.variable,
    );
  }
  if (json['color'] != null) {
    return FFill(
      levels: [
        FFillElement(
          color: (json['color'] as String).replaceAll('#', ''),
          stop: 0,
        ),
      ],
      type: FFillType.solid,
    );
  }
  if (json['pltt'] == null) {
    final levels = <FFillElement>[];
    var type = FFillType.solid;
    Alignment? begin, end, center;
    if (json['l'] != null) {
      for (final e in json['l'] as List<dynamic>) {
        levels.add(FFillElement.fromJson(json: e as Map<String, dynamic>));
      }
    }
    if (json['t'] != null) {
      if (json['t'] == 's') type = FFillType.solid;
      if (json['t'] == 'l') type = FFillType.linearGradient;
      if (json['t'] == 'r') type = FFillType.radialGradient;
      if (json['t'] == 'i') type = FFillType.image;
      if (json['t'] == 'n') type = FFillType.none;
    } else {
      type = FFillType.solid;
    }
    if (json['b'] != null) begin = alignFromJson(json, 'b');
    if (json['e'] != null) end = alignFromJson(json, 'e');
    if (json['c'] != null) center = alignFromJson(json, 'c');
    return FFill(
      levels: levels,
      type: type,
      begin: begin,
      end: end,
      center: center,
      radius: double.tryParse('${json['r']}') ?? 0,
      boxFit: FBoxFit.fromJson(json['bF'] as String),
    );
  } else {
    var value = json['pltt'] as String;
    if (value == 'Background / Blank') {
      value = 'Background / Primary';
    }
    return FFill(
      paletteStyle: value,
    );
  }
}