@@ -34,15 +34,15 @@ class ToolTipPositionDelegate extends SingleChildLayoutDelegate {
3434
3535 @override
3636 BoxConstraints getConstraintsForChild (BoxConstraints constraints) {
37- // TD: when margin is EdgeInsets, look into
38- // constraints.deflate(margin);
39- var newConstraints = this . constraints;
37+ // We use the INCOMING constraints (screen size) to calculate available space.
38+ // We do NOT start with this.constraints (user prefs) because that leads to negative math.
39+ var availableConstraints = constraints;
4040
4141 switch (preferredDirection) {
4242 case TooltipDirection .up:
4343 case TooltipDirection .down:
44- newConstraints = SuperUtils .verticalConstraints (
45- constraints: newConstraints ,
44+ availableConstraints = SuperUtils .verticalConstraints (
45+ constraints: availableConstraints ,
4646 margin: margin,
4747 bottom: bottom,
4848 isUp: preferredDirection == TooltipDirection .up,
@@ -54,8 +54,8 @@ class ToolTipPositionDelegate extends SingleChildLayoutDelegate {
5454 break ;
5555 case TooltipDirection .right:
5656 case TooltipDirection .left:
57- newConstraints = SuperUtils .horizontalConstraints (
58- constraints: newConstraints ,
57+ availableConstraints = SuperUtils .horizontalConstraints (
58+ constraints: availableConstraints ,
5959 margin: margin,
6060 bottom: bottom,
6161 isRight: preferredDirection == TooltipDirection .right,
@@ -67,40 +67,31 @@ class ToolTipPositionDelegate extends SingleChildLayoutDelegate {
6767 break ;
6868 }
6969
70- // TD: This scenerio should likely be avoided in the initial functions
71- // Ensure constraints are valid - no negiative values
72- final validatedConstraints = newConstraints.copyWith (
73- minHeight: math.max (
74- 0 ,
75- newConstraints.minHeight > newConstraints.maxHeight
76- ? newConstraints.maxHeight
77- : newConstraints.minHeight),
78- minWidth: math.max (
79- 0 ,
80- newConstraints.minWidth > newConstraints.maxWidth
81- ? newConstraints.maxWidth
82- : newConstraints.minWidth),
83- maxHeight: math.max (0 , newConstraints.maxHeight),
84- maxWidth: math.max (0 , newConstraints.maxWidth),
70+ // Now we merge the calculated "Available Space" with the User's "Desired Constraints".
71+ // We take the smaller of the two max widths/heights to ensure we fit in both.
72+ // We respect the user's min sizes unless they exceed available space.
73+
74+ double finalMaxWidth =
75+ math.min (availableConstraints.maxWidth, this .constraints.maxWidth);
76+ double finalMaxHeight =
77+ math.min (availableConstraints.maxHeight, this .constraints.maxHeight);
78+
79+ // Ensure final max is not negative
80+ finalMaxWidth = math.max (0.0 , finalMaxWidth);
81+ finalMaxHeight = math.max (0.0 , finalMaxHeight);
82+
83+ final validatedConstraints = BoxConstraints (
84+ minWidth: math.min (this .constraints.minWidth, finalMaxWidth),
85+ maxWidth: finalMaxWidth,
86+ minHeight: math.min (this .constraints.minHeight, finalMaxHeight),
87+ maxHeight: finalMaxHeight,
8588 );
8689
8790 return validatedConstraints;
8891 }
8992
9093 @override
9194 Offset getPositionForChild (Size size, Size childSize) {
92- // TD: If there isn't enough space for the child on the preferredDirection
93- // use the opposite dirrection
94- //
95- // See:
96- // return positionDependentBox(
97- // size: size,
98- // childSize: childSize,
99- // target: target,
100- // verticalOffset: verticalOffset,
101- // preferBelow: preferBelow,
102- // );
103-
10495 switch (preferredDirection) {
10596 case TooltipDirection .up:
10697 case TooltipDirection .down:
0 commit comments