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

added property "openWithTap: true|false" #8

Merged
merged 1 commit into from Nov 19, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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