Skip to content

feat: json string values for numbers #247

@aktxyz

Description

@aktxyz

In the code we have that eventually emits json ... everything pops out as a string ... like in this fontSize

          "child": {
            "data": "Home",
            "style": { "fontSize": "24" },
            "type": "text"
          },
          "type": "center"

Just to get past this one scenario, I tweaked the StacTextStyle fromJson to handle this. Can you all thing of a more clever way to handle this?

static StacTextStyle _fromJson(dynamic json) {
    if (json is String) {
      return _$StacTextStyleFromJson({"styleFromTheme": json});
    } else if (json is Map<String, dynamic>) {
      // if string, try parsing !!!!!!!!!!!!!!!!!!!!
      if (json['fontSize'] is String) {
        json['fontSize'] = double.tryParse(json['fontSize']);
      }
      return _$StacTextStyleFromJson(json);
    }

    return _$StacTextStyleFromJson({});
  }

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions