Rafa Ruiz

OnHover feature for Snackbars

... ... @@ -392,6 +392,7 @@ extension ExtensionSnackbar on GetInterface {
Gradient? backgroundGradient,
TextButton? mainButton,
OnTap? onTap,
OnHover? onHover,
bool? isDismissible,
bool? showProgressIndicator,
DismissDirection? dismissDirection,
... ... @@ -445,6 +446,7 @@ extension ExtensionSnackbar on GetInterface {
backgroundGradient: backgroundGradient,
mainButton: mainButton,
onTap: onTap,
onHover: onHover,
isDismissible: isDismissible ?? true,
dismissDirection: dismissDirection,
showProgressIndicator: showProgressIndicator ?? false,
... ...
... ... @@ -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);
... ... @@ -150,6 +151,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;
... ... @@ -259,6 +263,7 @@ class GetSnackBar extends StatefulWidget {
this.backgroundGradient,
this.mainButton,
this.onTap,
this.onHover,
this.duration,
this.isDismissible = true,
this.dismissDirection,
... ... @@ -657,3 +662,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 }
\ No newline at end of file
... ...
... ... @@ -238,11 +238,15 @@ class SnackbarController {
Widget _getBodyWidget() {
return Builder(builder: (_) {
return GestureDetector(
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,
),
);
});
}
... ...