From 8b8e55dadab81e4f97ac8c4e2f30628e479592a5 Mon Sep 17 00:00:00 2001 From: Sahil-Simform Date: Tue, 22 Oct 2024 13:47:18 +0530 Subject: [PATCH] =?UTF-8?q?=F0=9F=A9=B9Updated:=20Updated=20name=20of=20pa?= =?UTF-8?q?rameter=20and=20also=20added=20support=20for=20the=20floatingAc?= =?UTF-8?q?tion=20Widget=20for=20the=20default=20showcase=20widget?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- example/lib/main.dart | 42 +++++++++++++++++++++++++++++++++++-- lib/src/showcase.dart | 11 +++++----- lib/src/tooltip_widget.dart | 21 +++++++++++++++---- 3 files changed, 63 insertions(+), 11 deletions(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index 05b3703b..7f1781ae 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -225,6 +225,37 @@ class _MailPageState extends State { "Tap to see profile which contains user's name, profile picture, mobile number and country", tooltipBackgroundColor: Theme.of(context).primaryColor, textColor: Colors.white, + floatingActionWidget: Align( + alignment: Alignment.bottomLeft, + child: Padding( + padding: const EdgeInsets.all(16.0), + child: ElevatedButton( + style: ButtonStyle( + backgroundColor: MaterialStateProperty.all( + Theme.of(context).primaryColor), + shape: MaterialStateProperty.all< + RoundedRectangleBorder>( + RoundedRectangleBorder( + borderRadius: BorderRadius.circular(18.0), + side: BorderSide( + color: Theme.of(context).primaryColor, + width: 2.0, + ), + ), + ), + ), + child: const Text( + 'Skip Showcase', + style: TextStyle( + color: Colors.white, + fontSize: 15, + ), + ), + onPressed: () => + ShowCaseWidget.of(context).dismiss(), + ), + ), + ), targetShapeBorder: const CircleBorder(), child: Container( padding: const EdgeInsets.all(5), @@ -420,8 +451,9 @@ class MailTile extends StatelessWidget { targetBorderRadius: const BorderRadius.all( Radius.circular(150), ), - staticContainer: Column( + floatingActionWidget: Column( mainAxisAlignment: MainAxisAlignment.end, + crossAxisAlignment: CrossAxisAlignment.start, children: [ Padding( padding: const EdgeInsets.all(16.0), @@ -440,7 +472,13 @@ class MailTile extends StatelessWidget { ), ), ), - child: const Text('Skip Showcase'), + child: const Text( + 'Skip Showcase', + style: TextStyle( + color: Colors.white, + fontSize: 15, + ), + ), onPressed: () => ShowCaseWidget.of(context).dismiss(), ), diff --git a/lib/src/showcase.dart b/lib/src/showcase.dart index f644cd7a..7fffdb39 100644 --- a/lib/src/showcase.dart +++ b/lib/src/showcase.dart @@ -99,8 +99,9 @@ class Showcase extends StatefulWidget { /// Custom tooltip widget when [Showcase.withWidget] is used. final Widget? container; - /// Custom static tooltip widget when [Showcase.withWidget] is used. - final Widget? staticContainer; + /// Custom static floating action widget to show a static widget anywhere + /// on the screen + final Widget? floatingActionWidget; /// Defines background color for tooltip widget. /// @@ -291,10 +292,10 @@ class Showcase extends StatefulWidget { this.titleTextDirection, this.descriptionTextDirection, this.onBarrierClick, + this.floatingActionWidget, }) : height = null, width = null, container = null, - staticContainer = null, assert(overlayOpacity >= 0.0 && overlayOpacity <= 1.0, "overlay opacity must be between 0 and 1."), assert(onTargetClick == null || disposeOnTap != null, @@ -308,7 +309,7 @@ class Showcase extends StatefulWidget { required this.width, required this.container, required this.child, - this.staticContainer, + this.floatingActionWidget, this.targetShapeBorder = const RoundedRectangleBorder( borderRadius: BorderRadius.all( Radius.circular(8), @@ -556,7 +557,7 @@ class _ShowcaseState extends State { titleTextStyle: widget.titleTextStyle, descTextStyle: widget.descTextStyle, container: widget.container, - staticContainer: widget.staticContainer, + floatingActionWidget: widget.floatingActionWidget, tooltipBackgroundColor: widget.tooltipBackgroundColor, textColor: widget.textColor, showArrow: widget.showArrow, diff --git a/lib/src/tooltip_widget.dart b/lib/src/tooltip_widget.dart index 30943168..97b4c865 100644 --- a/lib/src/tooltip_widget.dart +++ b/lib/src/tooltip_widget.dart @@ -41,7 +41,7 @@ class ToolTipWidget extends StatefulWidget { final TextStyle? titleTextStyle; final TextStyle? descTextStyle; final Widget? container; - final Widget? staticContainer; + final Widget? floatingActionWidget; final Color? tooltipBackgroundColor; final Color? textColor; final bool showArrow; @@ -74,7 +74,7 @@ class ToolTipWidget extends StatefulWidget { required this.titleTextStyle, required this.descTextStyle, required this.container, - required this.staticContainer, + required this.floatingActionWidget, required this.tooltipBackgroundColor, required this.textColor, required this.showArrow, @@ -354,7 +354,7 @@ class _ToolTipWidgetState extends State } if (widget.container == null) { - return Positioned( + final defaultToolTipWidget = Positioned( top: contentY, left: _getLeft(), right: _getRight(), @@ -477,9 +477,22 @@ class _ToolTipWidgetState extends State ), ), ); + + if (widget.floatingActionWidget != null) { + return Stack( + fit: StackFit.expand, + children: [ + defaultToolTipWidget, + widget.floatingActionWidget!, + ], + ); + } else { + return defaultToolTipWidget; + } } return Stack( + fit: StackFit.expand, children: [ Positioned( left: _getSpace(), @@ -514,7 +527,7 @@ class _ToolTipWidgetState extends State ), ), ), - if (widget.staticContainer != null) ...[widget.staticContainer!], + if (widget.floatingActionWidget != null) widget.floatingActionWidget!, ], ); }