Skip to content

Commit

Permalink
Merge pull request #8 from ignaciotcrespo/onTap
Browse files Browse the repository at this point in the history
Added Property "openWithTap" (true/false) to open context menu on single tap
  • Loading branch information
retroportalstudio committed Nov 19, 2020
2 parents ca31135 + 12c3e37 commit 2c1477b
Showing 1 changed file with 56 additions and 29 deletions.
85 changes: 56 additions & 29 deletions lib/focused_menu.dart
Expand Up @@ -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
Expand All @@ -44,36 +60,47 @@ class _FocusedMenuHolderState extends State<FocusedMenuHolder> {
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));
}
}

Expand Down

0 comments on commit 2c1477b

Please sign in to comment.