Skip to content

Commit

Permalink
feat: ✨Added Hide functionality for global floating action widget
Browse files Browse the repository at this point in the history
  • Loading branch information
Sahil-Simform committed Dec 3, 2024
1 parent 64bae43 commit bff83f1
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 60 deletions.
43 changes: 22 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,27 +136,28 @@ WidgetsBinding.instance.addPostFrameCallback((_) =>

## Properties of `ShowCaseWidget`:

| Name | Type | Default Behaviour | Description |
|---------------------------|----------------------------|------------------------------|--------------------------------------------------------------------------------|
| builder | Builder | | |
| blurValue | double | 0 | Provides blur effect on overlay |
| autoPlay | bool | false | Automatically display Next showcase |
| autoPlayDelay | Duration | Duration(milliseconds: 2000) | Visibility time of showcase when `autoplay` is enabled |
| enableAutoPlayLock | bool | false | Block the user interaction on overlay when autoPlay is enabled. |
| enableAutoScroll | bool | false | Allows to auto scroll to next showcase so as to make the given target visible. |
| scrollDuration | Duration | Duration(milliseconds: 300) | Time duration for auto scrolling |
| disableBarrierInteraction | bool | false | Disable barrier interaction |
| disableScaleAnimation | bool | false | Disable scale transition for all showcases |
| disableMovingAnimation | bool | false | Disable bouncing/moving transition for all showcases |
| onStart | Function(int?, GlobalKey)? | | Triggered on start of each showcase. |
| onComplete | Function(int?, GlobalKey)? | | Triggered on completion of each showcase. |
| onFinish | VoidCallback? | | Triggered when all the showcases are completed |
| enableShowcase | bool | true | Enable or disable showcase globally. |
| toolTipMargin | double | 14 | For tooltip margin |
| globalTooltipActionConfig | TooltipActionConfig? | | Global tooltip actionbar config |
| globalTooltipActions | List<TooltipActionButton>? | | Global list of tooltip actions |
| scrollAlignment | double | 0.5 | For Auto scroll widget alignment |
| globalTooltipActionConfig | FloatingActionWidget | | Global Config for tooltip action to auto apply for all the toolTip |
| Name | Type | Default Behaviour | Description |
|-------------------------------------|----------------------------------------------|------------------------------|--------------------------------------------------------------------------------|
| builder | Builder | | |
| blurValue | double | 0 | Provides blur effect on overlay. |
| autoPlay | bool | false | Automatically display Next showcase. |
| autoPlayDelay | Duration | Duration(milliseconds: 2000) | Visibility time of showcase when `autoplay` is enabled. |
| enableAutoPlayLock | bool | false | Block the user interaction on overlay when autoPlay is enabled. |
| enableAutoScroll | bool | false | Allows to auto scroll to next showcase so as to make the given target visible. |
| scrollDuration | Duration | Duration(milliseconds: 300) | Time duration for auto scrolling. |
| disableBarrierInteraction | bool | false | Disable barrier interaction. |
| disableScaleAnimation | bool | false | Disable scale transition for all showcases. |
| disableMovingAnimation | bool | false | Disable bouncing/moving transition for all showcases. |
| onStart | Function(int?, GlobalKey)? | | Triggered on start of each showcase. |
| onComplete | Function(int?, GlobalKey)? | | Triggered on completion of each showcase. |
| onFinish | VoidCallback? | | Triggered when all the showcases are completed. |
| enableShowcase | bool | true | Enable or disable showcase globally. |
| toolTipMargin | double | 14 | For tooltip margin. |
| globalTooltipActionConfig | TooltipActionConfig? | | Global tooltip actionbar config. |
| globalTooltipActions | List<TooltipActionButton>? | | Global list of tooltip actions . |
| scrollAlignment | double | 0.5 | For Auto scroll widget alignment. |
| globalTooltipActionConfig | FloatingActionWidget Function(BuildContext)? | | Global Config for tooltip action to auto apply for all the toolTip . |
| hideFloatingActionWidgetForShowcase | List<GlobalKey> | [] | Hides globalFloatingActionWidget for the provided showcase widget keys. |


## Properties of `Showcase` and `Showcase.withWidget`:
Expand Down
63 changes: 27 additions & 36 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,27 @@ class MyApp extends StatelessWidget {
debugShowCheckedModeBanner: false,
home: Scaffold(
body: ShowCaseWidget(
hideFloatingActionWidgetForShowcase: [_lastShowcaseWidget],
globalFloatingActionWidget: (showcaseContext) => FloatingActionWidget(
left: 16,
bottom: 16,
child: Padding(
padding: const EdgeInsets.all(16.0),
child: ElevatedButton(
onPressed: () => ShowCaseWidget.of(showcaseContext).dismiss(),
style: ElevatedButton.styleFrom(
backgroundColor: const Color(0xffEE5366),
),
child: const Text(
'Skip',
style: TextStyle(
color: Colors.white,
fontSize: 15,
),
),
),
),
),
onStart: (index, key) {
log('onStart: $index, $key');
},
Expand Down Expand Up @@ -262,15 +283,17 @@ class _MailPageState extends State<MailPage> {
child: Padding(
padding: const EdgeInsets.all(16.0),
child: ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor: const Color(0xffEE5366),
),
onPressed: ShowCaseWidget.of(context).dismiss,
child: const Text(
'Skip Showcase',
'Close Showcase',
style: TextStyle(
color: Colors.pink,
color: Colors.white,
fontSize: 15,
),
),
onPressed: () =>
ShowCaseWidget.of(context).dismiss(),
),
),
),
Expand Down Expand Up @@ -582,38 +605,6 @@ class MailTile extends StatelessWidget {
targetBorderRadius: const BorderRadius.all(
Radius.circular(150),
),
floatingActionWidget: FloatingActionWidget.directional(
textDirection: Directionality.of(context),
start: 0,
bottom: 0,
child: Padding(
padding: const EdgeInsets.all(16.0),
child: ElevatedButton(
style: ButtonStyle(
backgroundColor: MaterialStateProperty.all<Color>(
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(),
),
),
),
container: Container(
padding: const EdgeInsets.all(10),
decoration: const BoxDecoration(
Expand Down
2 changes: 1 addition & 1 deletion lib/src/showcase.dart
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,7 @@ class _ShowcaseState extends State<Showcase> {
descTextStyle: widget.descTextStyle,
container: widget.container,
floatingActionWidget: widget.floatingActionWidget ??
showCaseWidgetState.widget.globalFloatingActionWidget,
showCaseWidgetState.globalFloatingActionWidget?.call(context),
tooltipBackgroundColor: widget.tooltipBackgroundColor,
textColor: widget.textColor,
showArrow: widget.showArrow,
Expand Down
20 changes: 18 additions & 2 deletions lib/src/showcase_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,21 @@ class ShowCaseWidget extends StatefulWidget {

/// Custom static floating action widget to show a static widget anywhere
/// on the screen for all the showcase widget
final FloatingActionWidget? globalFloatingActionWidget;
/// Use this context to access showcaseWidget operation otherwise it will
/// throw error.
final FloatingActionWidget Function(BuildContext)? globalFloatingActionWidget;

/// Global action to apply on every tooltip widget
final List<TooltipActionButton>? globalTooltipActions;

/// Global Config for tooltip action to auto apply for all the toolTip.
final TooltipActionConfig? globalTooltipActionConfig;

/// Hides [globalFloatingActionWidget] for the provided showcase widgets. Add key of
/// showcase in which [globalFloatingActionWidget] should be hidden this list.
/// Defaults to [].
final List<GlobalKey> hideFloatingActionWidgetForShowcase;

/// A widget that manages multiple Showcase widgets.
///
/// This widget provides a way to sequentially showcase multiple widgets
Expand All @@ -119,7 +126,8 @@ class ShowCaseWidget extends StatefulWidget {
/// - `enableShowcase`: Enables or disables the showcase functionality globally (defaults to `true`).
/// - `globalTooltipActions`: A list of custom actions to be added to all tooltips.
/// - `globalTooltipActionConfig`: Configuration options for the global tooltip actions.
/// - `floatingActionWidget`: Custom static floating action widget to show a static widget anywhere for all the showcase widgets
/// - `globalFloatingActionWidget`: Custom static floating action widget to show a static widget anywhere for all the showcase widgets.
/// - `hideFloatingActionWidgetForShowcase`: Hides a [globalFloatingActionWidget] for the provided showcase keys.
const ShowCaseWidget({
required this.builder,
this.onFinish,
Expand All @@ -138,6 +146,7 @@ class ShowCaseWidget extends StatefulWidget {
this.globalTooltipActionConfig,
this.globalTooltipActions,
this.globalFloatingActionWidget,
this.hideFloatingActionWidgetForShowcase = const [],
});

static GlobalKey? activeTargetWidget(BuildContext context) {
Expand Down Expand Up @@ -193,6 +202,13 @@ class ShowCaseWidgetState extends State<ShowCaseWidget> {
/// Returns value of [ShowCaseWidget.blurValue]
double get blurValue => widget.blurValue;

/// Return a [widget.globalFloatingActionWidget] if not need to hide this for
/// current showcase
FloatingActionWidget Function(BuildContext)? get globalFloatingActionWidget =>
widget.hideFloatingActionWidgetForShowcase.contains(ids![activeWidgetId!])
? null
: widget.globalFloatingActionWidget;

@override
void initState() {
super.initState();
Expand Down

0 comments on commit bff83f1

Please sign in to comment.