Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a feature when Hovering on web for Snackbar #2680

Merged
merged 3 commits into from
Feb 27, 2023
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
2 changes: 2 additions & 0 deletions lib/get_navigation/src/extension_navigation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,7 @@ extension ExtensionSnackbar on GetInterface {
Gradient? backgroundGradient,
TextButton? mainButton,
OnTap? onTap,
OnHover? onHover,
bool? isDismissible,
bool? showProgressIndicator,
DismissDirection? dismissDirection,
Expand Down Expand Up @@ -448,6 +449,7 @@ extension ExtensionSnackbar on GetInterface {
backgroundGradient: backgroundGradient,
mainButton: mainButton,
onTap: onTap,
onHover: onHover,
isDismissible: isDismissible ?? true,
dismissDirection: dismissDirection,
showProgressIndicator: showProgressIndicator ?? false,
Expand Down
8 changes: 8 additions & 0 deletions lib/get_navigation/src/snackbar/snackbar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import '../../../get_core/get_core.dart';
import '../../get_navigation.dart';

typedef OnTap = void Function(GetSnackBar snack);
typedef OnHover = void Function(GetSnackBar snack, SnackHoverState snackHoverState);

typedef SnackbarStatusCallback = void Function(SnackbarStatus? status);

Expand Down Expand Up @@ -71,6 +72,9 @@ class GetSnackBar extends StatefulWidget {
/// An alternative to [mainButton]
final OnTap? onTap;

/// A callback that registers the user's hover anywhere over the Snackbar.
final OnHover? onHover;

/// How long until Snack will hide itself (be dismissed).
/// To make it indefinite, leave it null.
final Duration? duration;
Expand Down Expand Up @@ -180,6 +184,7 @@ class GetSnackBar extends StatefulWidget {
this.backgroundGradient,
this.mainButton,
this.onTap,
this.onHover,
this.duration,
this.isDismissible = true,
this.dismissDirection,
Expand Down Expand Up @@ -578,3 +583,6 @@ enum SnackPosition { top, bottom }

/// Indicates if snack will be attached to the edge of the screen or not
enum SnackStyle { floating, grounded }

/// Indicates if the mouse entered or exited
enum SnackHoverState { entered, exited }
14 changes: 9 additions & 5 deletions lib/get_navigation/src/snackbar/snackbar_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -238,11 +238,15 @@ class SnackbarController {

Widget _getBodyWidget() {
return Builder(builder: (_) {
return GestureDetector(
onTap: snackbar.onTap != null
? () => snackbar.onTap?.call(snackbar)
: null,
child: snackbar,
return MouseRegion(
onEnter: (_) => snackbar.onHover?.call(snackbar, SnackHoverState.entered),
onExit: (_) => snackbar.onHover?.call(snackbar, SnackHoverState.exited),
child: GestureDetector(
child: snackbar,
onTap: snackbar.onTap != null
? () => snackbar.onTap?.call(snackbar)
: null,
),
);
});
}
Expand Down