@@ -124,6 +124,20 @@ class CornerRadius extends Equatable with DynamicSerializableMixin {
124124 /// Factory constructor for creating a new [CornerRadius] instance from
125125 /// JSON data.
126126 factory CornerRadius .fromJson (dynamic json) {
127+ if (json case [num radius, bool linked, String type]) {
128+ return CornerRadius .all (
129+ RadiusModel .circular (radius.toDouble ()),
130+ linked: linked,
131+ type: RadiusType .values.byName (type),
132+ );
133+ }
134+ if (json case [num x, num y, bool linked, String type]) {
135+ return CornerRadius .all (
136+ RadiusModel .elliptical (x.toDouble (), y.toDouble ()),
137+ linked: linked,
138+ type: RadiusType .values.byName (type),
139+ );
140+ }
127141 if (json is Iterable ) {
128142 return CornerRadius (
129143 tl: RadiusModel (
@@ -150,14 +164,33 @@ class CornerRadius extends Equatable with DynamicSerializableMixin {
150164 }
151165
152166 @override
153- dynamic toJson () => [
154- ...tl.toJson (),
155- ...tr.toJson (),
156- ...bl.toJson (),
157- ...br.toJson (),
167+ dynamic toJson () {
168+ if (type == RadiusType .elliptical) {
169+ return [
170+ tl.x.toPrettyPrecision (3 ),
171+ tl.y.toPrettyPrecision (3 ),
172+ linked,
173+ type.name,
174+ ];
175+ }
176+ if (tl == tr && tl == bl && tl == br) {
177+ return [
178+ tl.x.toPrettyPrecision (3 ),
179+ if (tl.x.toPrettyPrecision (3 ) != tl.y.toPrettyPrecision (3 ))
180+ tl.y.toPrettyPrecision (3 ),
158181 linked,
159182 type.name,
160183 ];
184+ }
185+ return [
186+ ...tl.toJson (),
187+ ...tr.toJson (),
188+ ...bl.toJson (),
189+ ...br.toJson (),
190+ linked,
191+ type.name,
192+ ];
193+ }
161194}
162195
163196/// A radius for either circular or elliptical shapes.
0 commit comments