Skip to content

Commit

Permalink
🐛 #105 showcase not showing text in one line even if it is not so big.
Browse files Browse the repository at this point in the history
  • Loading branch information
vatsaltanna-simformsolutions authored and BirjuVachhani committed Jun 4, 2021
1 parent 166a8cb commit 55ced45
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 4 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## [1.0.1] - March 07, 2021 [Unreleased]

- Fixed [#103](https://github.com/SimformSolutionsPvtLtd/flutter_showcaseview/issues/103) - add overlay padding.
- Fixed [#105](https://github.com/SimformSolutionsPvtLtd/flutter_showcaseview/issues/105) - showcase not showing text in one line even if it is not so big.

## [1.0.0] - March 07, 2021

- Fixed [#95](https://github.com/SimformSolutionsPvtLtd/flutter_showcaseview/issues/95) - Migrated to null safety.
Expand Down
3 changes: 2 additions & 1 deletion lib/src/showcase.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ class Showcase extends StatefulWidget {
this.disposeOnTap,
this.animationDuration = const Duration(milliseconds: 2000),
this.disableAnimation = false,
this.contentPadding = const EdgeInsets.symmetric(vertical: 8),
this.contentPadding =
const EdgeInsets.symmetric(vertical: 8, horizontal: 8),
this.onToolTipClick,
this.overlayPadding = EdgeInsets.zero})
: height = null,
Expand Down
34 changes: 31 additions & 3 deletions lib/src/tooltip_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class ToolTipWidget extends StatefulWidget {
this.contentHeight,
this.contentWidth,
this.onTooltipTap,
this.contentPadding});
this.contentPadding = const EdgeInsets.symmetric(vertical: 8)});

@override
_ToolTipWidgetState createState() => _ToolTipWidgetState();
Expand All @@ -91,8 +91,25 @@ class _ToolTipWidgetState extends State<ToolTipWidget> {
}

double _getTooltipWidth() {
final titleLength = widget.title == null ? 0 : widget.title!.length * 10.0;
final descriptionLength = widget.description!.length * 7.0;
final titleStyle = widget.titleTextStyle ??
Theme.of(context)
.textTheme
.headline6!
.merge(TextStyle(color: widget.textColor));
final descriptionStyle = widget.descTextStyle ??
Theme.of(context)
.textTheme
.subtitle2!
.merge(TextStyle(color: widget.textColor));
final titleLength = widget.title == null
? 0
: _textSize(widget.title!, titleStyle).width +
widget.contentPadding!.right +
widget.contentPadding!.left;
final descriptionLength =
_textSize(widget.description!, descriptionStyle).width +
widget.contentPadding!.right +
widget.contentPadding!.left;
var maxTextWidth = max(titleLength, descriptionLength);
if (maxTextWidth > widget.screenSize!.width - 20) {
return widget.screenSize!.width - 20;
Expand Down Expand Up @@ -326,4 +343,15 @@ class _ToolTipWidgetState extends State<ToolTipWidget> {
),
);
}

Size _textSize(String text, TextStyle style) {
final textPainter = (TextPainter(
text: TextSpan(text: text, style: style),
maxLines: 1,
textScaleFactor: MediaQuery.of(context).textScaleFactor,
textDirection: TextDirection.ltr)
..layout())
.size;
return textPainter;
}
}

0 comments on commit 55ced45

Please sign in to comment.