Skip to content

Commit

Permalink
Added a new way to redefine how we declare BorderRadius
Browse files Browse the repository at this point in the history
  • Loading branch information
divyanshub024 committed Mar 2, 2024
1 parent 7600243 commit 6274a8e
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 14 deletions.
7 changes: 1 addition & 6 deletions examples/mirai_gallery/assets/json/text_field_example.json
Original file line number Diff line number Diff line change
Expand Up @@ -246,12 +246,7 @@
"labelText": "Gradient TextField",
"border": {
"type": "outlineInputBorder",
"borderRadius": {
"topLeft": 8,
"topRight": 8,
"bottomLeft": 8,
"bottomRight": 8
},
"borderRadius": 80,
"gradient": {
"colors": [
"#FF0000",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,37 @@ class MiraiBorderRadius with _$MiraiBorderRadius {
@Default(0.0) double bottomRight,
}) = _MiraiBorder;

factory MiraiBorderRadius.fromJson(Map<String, dynamic> json) =>
_$MiraiBorderRadiusFromJson(json);
factory MiraiBorderRadius.fromJson(dynamic json) => _fromJson(json);

static MiraiBorderRadius _fromJson(dynamic json) {
Map<String, dynamic> resultantJson;

if (json is num) {
resultantJson = {
"topLeft": json,
"topRight": json,
"bottomLeft": json,
"bottomRight": json
};
} else if (json is List<dynamic> && 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<String, dynamic>) {
resultantJson = json;
} else {
throw ArgumentError('Invalid input format for MiraiEdgeInsets');
}

return _$MiraiBorderRadiusFromJson(resultantJson);
}
}

extension MiraiBorderRadiusParser on MiraiBorderRadius? {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6274a8e

Please sign in to comment.