From 12c3e379f6cbe4fd15a586c27662813e1d04d5ea Mon Sep 17 00:00:00 2001 From: Ignacio Tomas Crespo Date: Wed, 21 Oct 2020 00:03:47 +0200 Subject: [PATCH] added property "openWithTap: true|false" --- lib/focused_menu.dart | 85 ++++++++++++++++++++++++++++--------------- 1 file changed, 56 insertions(+), 29 deletions(-) diff --git a/lib/focused_menu.dart b/lib/focused_menu.dart index f1f0bac..fd5960d 100644 --- a/lib/focused_menu.dart +++ b/lib/focused_menu.dart @@ -17,8 +17,24 @@ class FocusedMenuHolder extends StatefulWidget { final Color blurBackgroundColor; final double bottomOffsetHeight; final double menuOffset; + /// Open with tap insted of long press. + final bool openWithTap; - const FocusedMenuHolder({Key key, @required this.child, @required this.onPressed, @required this.menuItems, this.duration, this.menuBoxDecoration, this.menuItemExtent, this.animateMenuItems,this.blurSize,this.blurBackgroundColor,this.menuWidth, this.bottomOffsetHeight, this.menuOffset}) + const FocusedMenuHolder( + {Key key, + @required this.child, + @required this.onPressed, + @required this.menuItems, + this.duration, + this.menuBoxDecoration, + this.menuItemExtent, + this.animateMenuItems, + this.blurSize, + this.blurBackgroundColor, + this.menuWidth, + this.bottomOffsetHeight, + this.menuOffset, + this.openWithTap = false}) : super(key: key); @override @@ -44,36 +60,47 @@ class _FocusedMenuHolderState extends State { Widget build(BuildContext context) { return GestureDetector( key: containerKey, - onTap: widget.onPressed, + onTap: () async { + widget.onPressed(); + if (widget.openWithTap) { + await openMenu(context); + } + }, onLongPress: () async { - getOffset(); - await Navigator.push( - context, - PageRouteBuilder( - transitionDuration: widget.duration ?? Duration(milliseconds: 100), - pageBuilder: (context, animation, secondaryAnimation) { - animation = Tween(begin: 0.0, end: 1.0).animate(animation); - return FadeTransition( - opacity: animation, - child: FocusedMenuDetails( - itemExtent: widget.menuItemExtent, - menuBoxDecoration: widget.menuBoxDecoration, - child: widget.child, - childOffset: childOffset, - childSize: childSize, - menuItems: widget.menuItems, - blurSize:widget.blurSize, - menuWidth:widget.menuWidth, - blurBackgroundColor: widget.blurBackgroundColor, - animateMenu: widget.animateMenuItems ?? true, - bottomOffsetHeight:widget.bottomOffsetHeight ?? 0, - menuOffset: widget.menuOffset ?? 0, - )); - }, - fullscreenDialog: true, - opaque: false)); + if (!widget.openWithTap) { + await openMenu(context); + } }, - child: widget.child); + child: widget.child); + } + + Future openMenu(BuildContext context) async { + getOffset(); + await Navigator.push( + context, + PageRouteBuilder( + transitionDuration: widget.duration ?? Duration(milliseconds: 100), + pageBuilder: (context, animation, secondaryAnimation) { + animation = Tween(begin: 0.0, end: 1.0).animate(animation); + return FadeTransition( + opacity: animation, + child: FocusedMenuDetails( + itemExtent: widget.menuItemExtent, + menuBoxDecoration: widget.menuBoxDecoration, + child: widget.child, + childOffset: childOffset, + childSize: childSize, + menuItems: widget.menuItems, + blurSize: widget.blurSize, + menuWidth: widget.menuWidth, + blurBackgroundColor: widget.blurBackgroundColor, + animateMenu: widget.animateMenuItems ?? true, + bottomOffsetHeight: widget.bottomOffsetHeight ?? 0, + menuOffset: widget.menuOffset ?? 0, + )); + }, + fullscreenDialog: true, + opaque: false)); } }