Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,25 @@ Create a callback function to dismiss
}
```

## MouseRegion on Desktop & Web
Based on issue [#80](https://github.com/bensonarafat/super_tooltip/issues/80) Supertooltip now support MouseEnter and Exit for Desktop for Web
### How to use
```dart
SuperTooltip(
// ... other parameters
showOnHover: true, // Tooltip appears on hover
hideOnHoverExit: true, // Tooltip disappears when mouse leaves
content: Text("Hello World"),
child: Icon(Icons.info),
);

```
<b>Demo</b>
<p>
<img src="https://private-user-images.githubusercontent.com/74812392/518725925-f425c7b1-fd4b-48ee-9a1b-079fe357f269.gif?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3NjU2MjY0MzEsIm5iZiI6MTc2NTYyNjEzMSwicGF0aCI6Ii83NDgxMjM5Mi81MTg3MjU5MjUtZjQyNWM3YjEtZmQ0Yi00OGVlLTlhMWItMDc5ZmUzNTdmMjY5LmdpZj9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTEyMTMlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUxMjEzVDExNDIxMVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWRlMjU1OWI5ODAwMjJhY2I4MjkyNzIzMGQwYzA4YjBkYTc5YjZkNDU3YTFhZDA0YzY3NDM1ZjE4ZjdhNWYyZTgmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.GWaIPrIgvwidohapOkdY3TMQsqOgowtxT33Y31zVtlw" width="200"/>
</p>
Thanks [@akhil-ge0rge](https://github.com/akhil-ge0rge)

## Example app

Find the example app [here](https://github.com/bensonarafat/super_tooltip/tree/master/example).
Expand Down
2 changes: 1 addition & 1 deletion android/local.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
sdk.dir=/Users/bensonarafat/Library/Android/sdk
flutter.sdk=/Users/bensonarafat/development/flutter
flutter.sdk=/Users/bensonarafat/development/flutter
1 change: 0 additions & 1 deletion example/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
# No lint rules for example
59 changes: 25 additions & 34 deletions lib/src/tooltip_position_delegate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ class ToolTipPositionDelegate extends SingleChildLayoutDelegate {

@override
BoxConstraints getConstraintsForChild(BoxConstraints constraints) {
// TD: when margin is EdgeInsets, look into
// constraints.deflate(margin);
var newConstraints = this.constraints;
// We use the INCOMING constraints (screen size) to calculate available space.
// We do NOT start with this.constraints (user prefs) because that leads to negative math.
var availableConstraints = constraints;

switch (preferredDirection) {
case TooltipDirection.up:
case TooltipDirection.down:
newConstraints = SuperUtils.verticalConstraints(
constraints: newConstraints,
availableConstraints = SuperUtils.verticalConstraints(
constraints: availableConstraints,
margin: margin,
bottom: bottom,
isUp: preferredDirection == TooltipDirection.up,
Expand All @@ -54,8 +54,8 @@ class ToolTipPositionDelegate extends SingleChildLayoutDelegate {
break;
case TooltipDirection.right:
case TooltipDirection.left:
newConstraints = SuperUtils.horizontalConstraints(
constraints: newConstraints,
availableConstraints = SuperUtils.horizontalConstraints(
constraints: availableConstraints,
margin: margin,
bottom: bottom,
isRight: preferredDirection == TooltipDirection.right,
Expand All @@ -67,40 +67,31 @@ class ToolTipPositionDelegate extends SingleChildLayoutDelegate {
break;
}

// TD: This scenerio should likely be avoided in the initial functions
// Ensure constraints are valid - no negiative values
final validatedConstraints = newConstraints.copyWith(
minHeight: math.max(
0,
newConstraints.minHeight > newConstraints.maxHeight
? newConstraints.maxHeight
: newConstraints.minHeight),
minWidth: math.max(
0,
newConstraints.minWidth > newConstraints.maxWidth
? newConstraints.maxWidth
: newConstraints.minWidth),
maxHeight: math.max(0, newConstraints.maxHeight),
maxWidth: math.max(0, newConstraints.maxWidth),
// Now we merge the calculated "Available Space" with the User's "Desired Constraints".
// We take the smaller of the two max widths/heights to ensure we fit in both.
// We respect the user's min sizes unless they exceed available space.

double finalMaxWidth =
math.min(availableConstraints.maxWidth, this.constraints.maxWidth);
double finalMaxHeight =
math.min(availableConstraints.maxHeight, this.constraints.maxHeight);

// Ensure final max is not negative
finalMaxWidth = math.max(0.0, finalMaxWidth);
finalMaxHeight = math.max(0.0, finalMaxHeight);

final validatedConstraints = BoxConstraints(
minWidth: math.min(this.constraints.minWidth, finalMaxWidth),
maxWidth: finalMaxWidth,
minHeight: math.min(this.constraints.minHeight, finalMaxHeight),
maxHeight: finalMaxHeight,
);

return validatedConstraints;
}

@override
Offset getPositionForChild(Size size, Size childSize) {
// TD: If there isn't enough space for the child on the preferredDirection
// use the opposite dirrection
//
// See:
// return positionDependentBox(
// size: size,
// childSize: childSize,
// target: target,
// verticalOffset: verticalOffset,
// preferBelow: preferBelow,
// );

switch (preferredDirection) {
case TooltipDirection.up:
case TooltipDirection.down:
Expand Down
24 changes: 16 additions & 8 deletions lib/src/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -153,18 +153,25 @@ class SuperUtils {

if (isRight) {
if (right != null) {
minWidth = maxWidth = maxWidth - right - target.dx;
// Calculate available width based on margin
maxWidth = maxWidth - right - target.dx;
// Don't force minWidth to be equal to maxWidth (allows shrinking)
} else {
maxWidth = min(maxWidth, maxWidth - target.dx) - margin;
maxWidth = (maxWidth - target.dx) - margin;
}
} else {
if (left != null) {
minWidth = maxWidth = target.dx - left;
// Calculate available width based on margin
maxWidth = target.dx - left;
} else {
maxWidth = min(maxWidth, target.dx) - margin;
}
}

// Robustness check to prevent negative constraints
if (maxWidth < 0) maxWidth = 0;
if (minWidth > maxWidth) minWidth = maxWidth;

return constraints.copyWith(
maxHeight: maxHeight,
minWidth: minWidth,
Expand All @@ -190,7 +197,6 @@ class SuperUtils {
maxWidth = maxWidth - (left + right);
} else if ((left != null && right == null) ||
(left == null && right != null)) {
// make sure that the sum of left, right + maxwidth isn't bigger than the screen width.
final sideDelta = (left ?? 0.0) + (right ?? 0.0) + margin;

if (maxWidth > maxWidth - sideDelta) {
Expand All @@ -204,20 +210,22 @@ class SuperUtils {

if (isUp) {
if (top != null) {
minHeight = maxHeight = target.dy - top;
maxHeight = target.dy - top;
} else {
maxHeight = min(maxHeight, target.dy) - margin;
// TD: clamp minheight
}
} else {
if (bottom != null) {
minHeight = maxHeight = maxHeight - bottom - target.dy;
maxHeight = maxHeight - bottom - target.dy;
} else {
maxHeight = min(maxHeight, maxHeight - target.dy) - margin;
// TD: clamp minheight
}
}

// Robustness check
if (maxHeight < 0) maxHeight = 0;
if (minHeight > maxHeight) minHeight = maxHeight;

return constraints.copyWith(
minHeight: minHeight,
maxHeight: maxHeight,
Expand Down