Skip to content

Commit 8a174fb

Browse files
SaadArdatiBirjuVachhani
authored andcommitted
Fix resolvedConstraints where not properly calculated for images.
1 parent 4d0d489 commit 8a174fb

11 files changed

+35
-65
lines changed

lib/src/api/mixins.dart

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -591,39 +591,34 @@ mixin GeometryMixin on BaseNode {
591591
if (fill.type != PaintType.image) continue;
592592
if ((fill.sourceWidth != null && fill.sourceHeight != null) ||
593593
(fill.cropData != null)) {
594-
final SizeC currentSize = SizeC(
595-
fill.cropData?.width ?? fill.sourceWidth ?? 0,
596-
fill.cropData?.height ?? fill.sourceHeight ?? 0,
597-
);
598-
SizeC size = SizeC.zero;
594+
final double? imgWidth =
595+
(fill.cropData?.width ?? fill.sourceWidth)?.roundToDouble();
596+
final double? imgHeight =
597+
(fill.cropData?.height ?? fill.sourceHeight)?.roundToDouble();
598+
599+
double? width, height;
599600
if (horizontalFit == SizeFit.shrinkWrap &&
600601
verticalFit == SizeFit.shrinkWrap) {
601-
size = SizeC(currentSize.width.roundToDouble(),
602-
currentSize.height.roundToDouble());
603-
} else {
602+
width = imgWidth;
603+
height = imgHeight;
604+
} else if (imgWidth != null && imgHeight != null) {
604605
// If this image vertically shrinkwraps, then we want to set the
605606
// minimum height to be equal to or less than the source height,
606607
// preserving aspect ratio with respect to the current node width.
607608
if (verticalFit == SizeFit.shrinkWrap) {
608-
size = SizeC(
609-
size.width,
610-
(currentSize.height * (basicBoxLocal.width / currentSize.width))
611-
.roundToDouble(),
612-
);
609+
height =
610+
(imgHeight * (basicBoxLocal.width / imgWidth)).roundToDouble();
613611
}
614612
if (horizontalFit == SizeFit.shrinkWrap) {
615-
size = SizeC(
616-
(currentSize.width * (basicBoxLocal.height / currentSize.height))
617-
.roundToDouble(),
618-
size.height,
619-
);
613+
width =
614+
(imgWidth * (basicBoxLocal.height / imgHeight)).roundToDouble();
620615
}
621616
}
622617

623-
resultSize = resultSize.enforce(
618+
resultSize = resultSize.union(
624619
BoxConstraintsModel(
625-
minWidth: size.width,
626-
minHeight: size.height,
620+
minWidth: width,
621+
minHeight: height,
627622
),
628623
);
629624
}

lib/src/api/models/box_constraints.dart

Lines changed: 7 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,13 @@ class BoxConstraintsModel with EquatableMixin, SerializableMixin {
194194
/// Creates a union [BoxConstraintsModel] from the current
195195
/// [BoxConstraintsModel] and the provided [constraints].
196196
///
197-
/// The resulting [BoxConstraintsModel] will have the minimum with and height
198-
/// that's the biggest of the two, and the maximum width and height that's
199-
/// the smallest of the two.
197+
/// The resulting [BoxConstraintsModel] will have:
198+
/// - The maximum of the two minimum widths.
199+
/// - The maximum of the two minimum heights.
200+
/// - The minimum of the two maximum widths.
201+
/// - The minimum of the two maximum heights.
202+
///
203+
/// [returns] a [BoxConstraintsModel] that has overlapping constraints.
200204
BoxConstraintsModel union(BoxConstraintsModel constraints) {
201205
return BoxConstraintsModel(
202206
minWidth: (minWidth == null)
@@ -222,35 +226,6 @@ class BoxConstraintsModel with EquatableMixin, SerializableMixin {
222226
);
223227
}
224228

225-
/// Similar to [union], but will only clamp the minimums and maximums
226-
/// if the passed [constraints] of the relevant parameter is not null.
227-
///
228-
/// So for example, if the passed [constraints] has a null min width,
229-
/// instead of returning a [BoxConstraintsModel] with a null min width,
230-
/// it just returns its own if available.
231-
/// Otherwise, it takes the biggest of the two min widths.
232-
///
233-
/// Another example, if the passed [constraints] has a null max width,
234-
/// instead of returning a [BoxConstraintsModel] with a null max width,
235-
/// it just returns its own if available.
236-
/// Otherwise, it takes the smallest of the two max widths.
237-
BoxConstraintsModel unionNonNull(BoxConstraintsModel constraints) {
238-
return BoxConstraintsModel(
239-
minWidth: constraints.minWidth == null
240-
? minWidth
241-
: max(minWidth ?? 0, constraints.minWidth!),
242-
maxWidth: constraints.maxWidth == null
243-
? maxWidth
244-
: min(maxWidth ?? double.infinity, constraints.maxWidth!),
245-
minHeight: constraints.minHeight == null
246-
? minHeight
247-
: max(minHeight ?? 0, constraints.minHeight!),
248-
maxHeight: constraints.maxHeight == null
249-
? maxHeight
250-
: min(maxHeight ?? double.infinity, constraints.maxHeight!),
251-
);
252-
}
253-
254229
/// Whether this constraints is the same as no constraints which is the
255230
/// default value.
256231
bool get isDefault =>

lib/src/api/node_processor.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,12 +192,12 @@ class NodeProcessor {
192192
parent.relegatedConstraintsToChildren(node);
193193
if (relegatedConstraints != null) {
194194
final parentResolved =
195-
relegatedConstraints.unionNonNull(resolveConstraints(parent));
196-
resolved = resolved.unionNonNull(parentResolved);
195+
relegatedConstraints.union(resolveConstraints(parent));
196+
resolved = resolved.union(parentResolved);
197197
}
198198
}
199199

200-
return node.constraints.unionNonNull(resolved);
200+
return node.constraints.union(resolved);
201201
}
202202

203203
/// Update the global rotation for given [node] with [newRotationDegrees].

lib/src/api/nodes/app_bar_node.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class AppBarNode extends SceneNode
8181
return super
8282
.internalConstraints(
8383
horizontalFit: horizontalFit, verticalFit: verticalFit)
84-
.unionNonNull(
84+
.union(
8585
BoxConstraintsModel(minHeight: minHeight),
8686
);
8787
}

lib/src/api/nodes/button_node.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ class ButtonNode extends SceneNode
154154
horizontalFit: horizontalFit,
155155
verticalFit: verticalFit,
156156
)
157-
.unionNonNull(
157+
.union(
158158
BoxConstraintsModel(
159159
minWidth: minSize.width,
160160
minHeight: minSize.height,

lib/src/api/nodes/divider_node.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ class DividerNode extends SceneNode with CustomPropertiesMixin {
109109
horizontalFit: horizontalFit,
110110
verticalFit: verticalFit,
111111
)
112-
.unionNonNull(
112+
.union(
113113
BoxConstraintsModel(
114114
minWidth: width,
115115
minHeight: height,

lib/src/api/nodes/dropdown_node.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class DropdownNode extends SceneNode with CustomPropertiesMixin {
6262
horizontalFit: horizontalFit,
6363
verticalFit: verticalFit,
6464
)
65-
.unionNonNull(BoxConstraintsModel(minWidth: iconSize));
65+
.union(BoxConstraintsModel(minWidth: iconSize));
6666
}
6767

6868
/// Creates a [DropdownNode] from a JSON object.

lib/src/api/nodes/loading_indicator_node.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class LoadingIndicatorNode extends SceneNode
8181
return super
8282
.internalConstraints(
8383
horizontalFit: horizontalFit, verticalFit: verticalFit)
84-
.unionNonNull(const BoxConstraintsModel(minWidth: 2, minHeight: 2));
84+
.union(const BoxConstraintsModel(minWidth: 2, minHeight: 2));
8585
}
8686

8787
@override

lib/src/api/nodes/navigation_bar_node.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ class NavigationBarNode extends SceneNode
248248
horizontalFit: horizontalFit,
249249
verticalFit: verticalFit,
250250
)
251-
.unionNonNull(
251+
.union(
252252
BoxConstraintsModel(
253253
minHeight:
254254
max(minHeight, kDefaultBottomNavigationBarHeight) + 1,
@@ -271,7 +271,7 @@ class NavigationBarNode extends SceneNode
271271
horizontalFit: horizontalFit,
272272
verticalFit: verticalFit,
273273
)
274-
.unionNonNull(
274+
.union(
275275
BoxConstraintsModel(minHeight: minHeight),
276276
);
277277
}

lib/src/api/nodes/single_placeholder_node.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class SinglePlaceholderNode extends SceneNode
2626
final superRelegated = super.relegatedConstraintsToChildren(child);
2727
return superRelegated == null
2828
? constraints
29-
: superRelegated.unionNonNull(constraints);
29+
: superRelegated.union(constraints);
3030
}
3131

3232
/// The node types that are allowed to be inside this [SinglePlaceholderNode].

0 commit comments

Comments
 (0)