diff --git a/examples/mirai_gallery/assets/json/text_field_example.json b/examples/mirai_gallery/assets/json/text_field_example.json index e96fdd70..37d6eea0 100644 --- a/examples/mirai_gallery/assets/json/text_field_example.json +++ b/examples/mirai_gallery/assets/json/text_field_example.json @@ -246,12 +246,7 @@ "labelText": "Gradient TextField", "border": { "type": "outlineInputBorder", - "borderRadius": { - "topLeft": 8, - "topRight": 8, - "bottomLeft": 8, - "bottomRight": 8 - }, + "borderRadius": 80, "gradient": { "colors": [ "#FF0000", diff --git a/packages/mirai/lib/src/parsers/mirai_border_radius/mirai_border_radius.dart b/packages/mirai/lib/src/parsers/mirai_border_radius/mirai_border_radius.dart index fde28f83..47fbfd18 100644 --- a/packages/mirai/lib/src/parsers/mirai_border_radius/mirai_border_radius.dart +++ b/packages/mirai/lib/src/parsers/mirai_border_radius/mirai_border_radius.dart @@ -13,8 +13,37 @@ class MiraiBorderRadius with _$MiraiBorderRadius { @Default(0.0) double bottomRight, }) = _MiraiBorder; - factory MiraiBorderRadius.fromJson(Map json) => - _$MiraiBorderRadiusFromJson(json); + factory MiraiBorderRadius.fromJson(dynamic json) => _fromJson(json); + + static MiraiBorderRadius _fromJson(dynamic json) { + Map resultantJson; + + if (json is num) { + resultantJson = { + "topLeft": json, + "topRight": json, + "bottomLeft": json, + "bottomRight": json + }; + } else if (json is List && json.length == 4) { + bool allElementsNum = json.every((element) => element is num); + if (!allElementsNum) { + throw ArgumentError('Invalid input format for MiraiEdgeInsets'); + } + resultantJson = { + "topLeft": json[0], + "topRight": json[1], + "bottomLeft": json[2], + "bottomRight": json[3] + }; + } else if (json is Map) { + resultantJson = json; + } else { + throw ArgumentError('Invalid input format for MiraiEdgeInsets'); + } + + return _$MiraiBorderRadiusFromJson(resultantJson); + } } extension MiraiBorderRadiusParser on MiraiBorderRadius? { diff --git a/packages/mirai/lib/src/parsers/mirai_box_decoration/mirai_box_decoration.g.dart b/packages/mirai/lib/src/parsers/mirai_box_decoration/mirai_box_decoration.g.dart index e351d611..3aaa751d 100644 --- a/packages/mirai/lib/src/parsers/mirai_box_decoration/mirai_box_decoration.g.dart +++ b/packages/mirai/lib/src/parsers/mirai_box_decoration/mirai_box_decoration.g.dart @@ -24,8 +24,7 @@ _$MiraiBoxDecorationImpl _$$MiraiBoxDecorationImplFromJson( : MiraiBorder.fromJson(json['border'] as Map), borderRadius: json['borderRadius'] == null ? null - : MiraiBorderRadius.fromJson( - json['borderRadius'] as Map), + : MiraiBorderRadius.fromJson(json['borderRadius']), image: json['image'] == null ? null : MiraiDecorationImage.fromJson( diff --git a/packages/mirai/lib/src/parsers/mirai_input_border/mirai_input_border.g.dart b/packages/mirai/lib/src/parsers/mirai_input_border/mirai_input_border.g.dart index 4936236a..4e16d044 100644 --- a/packages/mirai/lib/src/parsers/mirai_input_border/mirai_input_border.g.dart +++ b/packages/mirai/lib/src/parsers/mirai_input_border/mirai_input_border.g.dart @@ -13,8 +13,7 @@ _$MiraiInputBorderImpl _$$MiraiInputBorderImplFromJson( MiraiInputBorderType.underlineInputBorder, borderRadius: json['borderRadius'] == null ? null - : MiraiBorderRadius.fromJson( - json['borderRadius'] as Map), + : MiraiBorderRadius.fromJson(json['borderRadius']), gapPadding: (json['gapPadding'] as num?)?.toDouble() ?? 4.0, width: (json['width'] as num?)?.toDouble() ?? 0.0, color: json['color'] as String?, diff --git a/packages/mirai/lib/src/parsers/mirai_rounded_rectangle_border/mirai_rounded_rectangle_border.g.dart b/packages/mirai/lib/src/parsers/mirai_rounded_rectangle_border/mirai_rounded_rectangle_border.g.dart index fe142de0..531ee33b 100644 --- a/packages/mirai/lib/src/parsers/mirai_rounded_rectangle_border/mirai_rounded_rectangle_border.g.dart +++ b/packages/mirai/lib/src/parsers/mirai_rounded_rectangle_border/mirai_rounded_rectangle_border.g.dart @@ -14,8 +14,7 @@ _$MiraiRoundedRectangleBorderImpl _$$MiraiRoundedRectangleBorderImplFromJson( : MiraiBorderSide.fromJson(json['side'] as Map), borderRadius: json['borderRadius'] == null ? null - : MiraiBorderRadius.fromJson( - json['borderRadius'] as Map), + : MiraiBorderRadius.fromJson(json['borderRadius']), ); Map _$$MiraiRoundedRectangleBorderImplToJson(