From 55ced45a0b216351a38af223e4e3f84edb05f828 Mon Sep 17 00:00:00 2001 From: Vatsal Tanna Date: Fri, 4 Jun 2021 14:22:13 +0530 Subject: [PATCH] :bug: #105 showcase not showing text in one line even if it is not so big. --- CHANGELOG.md | 5 +++++ lib/src/showcase.dart | 3 ++- lib/src/tooltip_widget.dart | 34 +++++++++++++++++++++++++++++++--- 3 files changed, 38 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 934bb3b6..da32917d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/lib/src/showcase.dart b/lib/src/showcase.dart index cc4f72b3..0a18c86d 100644 --- a/lib/src/showcase.dart +++ b/lib/src/showcase.dart @@ -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, diff --git a/lib/src/tooltip_widget.dart b/lib/src/tooltip_widget.dart index 3ba4c9c2..0f5144a0 100644 --- a/lib/src/tooltip_widget.dart +++ b/lib/src/tooltip_widget.dart @@ -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(); @@ -91,8 +91,25 @@ class _ToolTipWidgetState extends State { } 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; @@ -326,4 +343,15 @@ class _ToolTipWidgetState extends State { ), ); } + + 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; + } }