Committed by
GitHub
Merge pull request #2680 from RafaRuiz/feature/hover_snackbar
Add a feature when Hovering on web for Snackbar
Showing
3 changed files
with
19 additions
and
5 deletions
@@ -395,6 +395,7 @@ extension ExtensionSnackbar on GetInterface { | @@ -395,6 +395,7 @@ extension ExtensionSnackbar on GetInterface { | ||
395 | Gradient? backgroundGradient, | 395 | Gradient? backgroundGradient, |
396 | TextButton? mainButton, | 396 | TextButton? mainButton, |
397 | OnTap? onTap, | 397 | OnTap? onTap, |
398 | + OnHover? onHover, | ||
398 | bool? isDismissible, | 399 | bool? isDismissible, |
399 | bool? showProgressIndicator, | 400 | bool? showProgressIndicator, |
400 | DismissDirection? dismissDirection, | 401 | DismissDirection? dismissDirection, |
@@ -448,6 +449,7 @@ extension ExtensionSnackbar on GetInterface { | @@ -448,6 +449,7 @@ extension ExtensionSnackbar on GetInterface { | ||
448 | backgroundGradient: backgroundGradient, | 449 | backgroundGradient: backgroundGradient, |
449 | mainButton: mainButton, | 450 | mainButton: mainButton, |
450 | onTap: onTap, | 451 | onTap: onTap, |
452 | + onHover: onHover, | ||
451 | isDismissible: isDismissible ?? true, | 453 | isDismissible: isDismissible ?? true, |
452 | dismissDirection: dismissDirection, | 454 | dismissDirection: dismissDirection, |
453 | showProgressIndicator: showProgressIndicator ?? false, | 455 | showProgressIndicator: showProgressIndicator ?? false, |
@@ -7,6 +7,7 @@ import '../../../get_core/get_core.dart'; | @@ -7,6 +7,7 @@ import '../../../get_core/get_core.dart'; | ||
7 | import '../../get_navigation.dart'; | 7 | import '../../get_navigation.dart'; |
8 | 8 | ||
9 | typedef OnTap = void Function(GetSnackBar snack); | 9 | typedef OnTap = void Function(GetSnackBar snack); |
10 | +typedef OnHover = void Function(GetSnackBar snack, SnackHoverState snackHoverState); | ||
10 | 11 | ||
11 | typedef SnackbarStatusCallback = void Function(SnackbarStatus? status); | 12 | typedef SnackbarStatusCallback = void Function(SnackbarStatus? status); |
12 | 13 | ||
@@ -71,6 +72,9 @@ class GetSnackBar extends StatefulWidget { | @@ -71,6 +72,9 @@ class GetSnackBar extends StatefulWidget { | ||
71 | /// An alternative to [mainButton] | 72 | /// An alternative to [mainButton] |
72 | final OnTap? onTap; | 73 | final OnTap? onTap; |
73 | 74 | ||
75 | + /// A callback that registers the user's hover anywhere over the Snackbar. | ||
76 | + final OnHover? onHover; | ||
77 | + | ||
74 | /// How long until Snack will hide itself (be dismissed). | 78 | /// How long until Snack will hide itself (be dismissed). |
75 | /// To make it indefinite, leave it null. | 79 | /// To make it indefinite, leave it null. |
76 | final Duration? duration; | 80 | final Duration? duration; |
@@ -180,6 +184,7 @@ class GetSnackBar extends StatefulWidget { | @@ -180,6 +184,7 @@ class GetSnackBar extends StatefulWidget { | ||
180 | this.backgroundGradient, | 184 | this.backgroundGradient, |
181 | this.mainButton, | 185 | this.mainButton, |
182 | this.onTap, | 186 | this.onTap, |
187 | + this.onHover, | ||
183 | this.duration, | 188 | this.duration, |
184 | this.isDismissible = true, | 189 | this.isDismissible = true, |
185 | this.dismissDirection, | 190 | this.dismissDirection, |
@@ -578,3 +583,6 @@ enum SnackPosition { top, bottom } | @@ -578,3 +583,6 @@ enum SnackPosition { top, bottom } | ||
578 | 583 | ||
579 | /// Indicates if snack will be attached to the edge of the screen or not | 584 | /// Indicates if snack will be attached to the edge of the screen or not |
580 | enum SnackStyle { floating, grounded } | 585 | enum SnackStyle { floating, grounded } |
586 | + | ||
587 | +/// Indicates if the mouse entered or exited | ||
588 | +enum SnackHoverState { entered, exited } |
@@ -238,11 +238,15 @@ class SnackbarController { | @@ -238,11 +238,15 @@ class SnackbarController { | ||
238 | 238 | ||
239 | Widget _getBodyWidget() { | 239 | Widget _getBodyWidget() { |
240 | return Builder(builder: (_) { | 240 | return Builder(builder: (_) { |
241 | - return GestureDetector( | ||
242 | - onTap: snackbar.onTap != null | ||
243 | - ? () => snackbar.onTap?.call(snackbar) | ||
244 | - : null, | ||
245 | - child: snackbar, | 241 | + return MouseRegion( |
242 | + onEnter: (_) => snackbar.onHover?.call(snackbar, SnackHoverState.entered), | ||
243 | + onExit: (_) => snackbar.onHover?.call(snackbar, SnackHoverState.exited), | ||
244 | + child: GestureDetector( | ||
245 | + child: snackbar, | ||
246 | + onTap: snackbar.onTap != null | ||
247 | + ? () => snackbar.onTap?.call(snackbar) | ||
248 | + : null, | ||
249 | + ), | ||
246 | ); | 250 | ); |
247 | }); | 251 | }); |
248 | } | 252 | } |
-
Please register or login to post a comment