relocateSecondary method
Relocates the secondary view accounting the possible intersections.
Implementation
void relocateSecondary() {
if (secondaryAlignment.value == null &&
secondaryDragged.isFalse &&
!_secondaryRelocated) {
_secondaryRelocated = true;
Rect? secondaryBounds, dockBounds;
try {
secondaryBounds = secondaryKey.globalPaintBounds;
dockBounds = dockKey.globalPaintBounds;
} catch (_) {
// No-op.
}
Rect intersect =
secondaryBounds?.intersect(dockBounds ?? Rect.zero) ?? Rect.zero;
intersect = Rect.fromLTWH(
intersect.left,
intersect.top,
intersect.width,
intersect.height + 10,
);
if (intersect.width > 0 && intersect.height > 0) {
secondaryBottomShifted ??=
secondaryBottom.value ??
size.height - secondaryTop.value! - secondaryHeight.value;
// Intersection is non-zero, so move the secondary panel up.
if (secondaryBottom.value != null) {
secondaryBottom.value = secondaryBottom.value! + intersect.height;
} else {
secondaryTop.value = secondaryTop.value! - intersect.height;
}
applySecondaryConstraints();
} else if ((intersect.height < 0 || intersect.width < 0) &&
secondaryBottomShifted != null) {
// Intersection is less than zero and the secondary panel is higher than
// it was before, so move it to its original position.
double bottom =
secondaryBottom.value ??
size.height - secondaryTop.value! - secondaryHeight.value;
if (bottom > secondaryBottomShifted!) {
double difference = bottom - secondaryBottomShifted!;
if (secondaryBottom.value != null) {
if (difference.abs() < intersect.height.abs() ||
intersect.width < 0) {
secondaryBottom.value = secondaryBottomShifted;
secondaryBottomShifted = null;
} else {
secondaryBottom.value =
secondaryBottom.value! - intersect.height.abs();
}
} else {
if (difference.abs() < intersect.height.abs() ||
intersect.width < 0) {
secondaryTop.value =
size.height - secondaryHeight.value - secondaryBottomShifted!;
secondaryBottomShifted = null;
} else {
secondaryTop.value = secondaryTop.value! + intersect.height.abs();
}
}
applySecondaryConstraints();
}
}
SchedulerBinding.instance.addPostFrameCallback(
(_) => _secondaryRelocated = false,
);
}
}