Skip to content

Commit 7ee89ab

Browse files
committed
Pub Version Update
2 parents 4ce1c2b + 2c1477b commit 7ee89ab

File tree

6 files changed

+70
-83
lines changed

6 files changed

+70
-83
lines changed

CHANGELOG.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,8 @@
66
## [1.0.1] - June 24,2020
77

88
* Added Customizable offset of Menu from Selected Item
9-
* Added BottomOffsetHeight for Screens with Bottom Navigation Bar
9+
* Added BottomOffsetHeight for Screens with Bottom Navigation Bar
10+
11+
## [1.0.2] - December 23,2020
12+
13+
* Added openWithTap: true|false to Open Focused Menu on Tap rather than a Long Press

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ To Use, simply Wrap the Widget you want to add Focused Menu to, with FocusedMenu
2828
duration: Duration(milliseconds: 100),
2929
animateMenuItems: true,
3030
blurBackgroundColor: Colors.black54,
31+
openWithTap: true, // Open Focused-Menu on Tap rather than Long Press
3132
menuOffset: 10.0, // Offset value to show menuItem from the selected item
3233
bottomOffsetHeight: 80.0, // Offset height to consider, for showing the menu item ( for example bottom navigation bar), so that the popup menu will be shown on top of selected item.
3334
menuItems: <FocusedMenuItem>[

example/lib/main.dart

+1
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ class MyHomePage extends StatelessWidget {
8888
animateMenuItems: true,
8989
blurBackgroundColor: Colors.black54,
9090
bottomOffsetHeight: 100,
91+
openWithTap: true,
9192
menuItems: <FocusedMenuItem>[
9293
FocusedMenuItem(title: Text("Open"),trailingIcon: Icon(Icons.open_in_new) ,onPressed: (){
9394
Navigator.push(context, MaterialPageRoute(builder: (context)=>ScreenTwo()));

example/pubspec.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ packages:
7373
path: ".."
7474
relative: true
7575
source: path
76-
version: "1.0.1"
76+
version: "1.0.2"
7777
matcher:
7878
dependency: transitive
7979
description:

lib/focused_menu.dart

+61-80
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ class FocusedMenuHolder extends StatefulWidget {
1717
final Color blurBackgroundColor;
1818
final double bottomOffsetHeight;
1919
final double menuOffset;
20+
/// Open with tap insted of long press.
21+
final bool openWithTap;
2022

2123
const FocusedMenuHolder(
2224
{Key key,
@@ -31,7 +33,8 @@ class FocusedMenuHolder extends StatefulWidget {
3133
this.blurBackgroundColor,
3234
this.menuWidth,
3335
this.bottomOffsetHeight,
34-
this.menuOffset})
36+
this.menuOffset,
37+
this.openWithTap = false})
3538
: super(key: key);
3639

3740
@override
@@ -43,7 +46,7 @@ class _FocusedMenuHolderState extends State<FocusedMenuHolder> {
4346
Offset childOffset = Offset(0, 0);
4447
Size childSize;
4548

46-
getOffset() {
49+
getOffset(){
4750
RenderBox renderBox = containerKey.currentContext.findRenderObject();
4851
Size size = renderBox.size;
4952
Offset offset = renderBox.localToGlobal(Offset.zero);
@@ -57,38 +60,48 @@ class _FocusedMenuHolderState extends State<FocusedMenuHolder> {
5760
Widget build(BuildContext context) {
5861
return GestureDetector(
5962
key: containerKey,
60-
onTap: widget.onPressed,
63+
onTap: () async {
64+
widget.onPressed();
65+
if (widget.openWithTap) {
66+
await openMenu(context);
67+
}
68+
},
6169
onLongPress: () async {
62-
getOffset();
63-
await Navigator.push(
64-
context,
65-
PageRouteBuilder(
66-
transitionDuration:
67-
widget.duration ?? Duration(milliseconds: 100),
68-
pageBuilder: (context, animation, secondaryAnimation) {
69-
animation = Tween(begin: 0.0, end: 1.0).animate(animation);
70-
return FadeTransition(
71-
opacity: animation,
72-
child: FocusedMenuDetails(
73-
itemExtent: widget.menuItemExtent,
74-
menuBoxDecoration: widget.menuBoxDecoration,
75-
child: widget.child,
76-
childOffset: childOffset,
77-
childSize: childSize,
78-
menuItems: widget.menuItems,
79-
blurSize: widget.blurSize,
80-
menuWidth: widget.menuWidth,
81-
blurBackgroundColor: widget.blurBackgroundColor,
82-
animateMenu: widget.animateMenuItems ?? true,
83-
bottomOffsetHeight: widget.bottomOffsetHeight ?? 0,
84-
menuOffset: widget.menuOffset ?? 0,
85-
));
86-
},
87-
fullscreenDialog: true,
88-
opaque: false));
70+
if (!widget.openWithTap) {
71+
await openMenu(context);
72+
}
8973
},
9074
child: widget.child);
9175
}
76+
77+
Future openMenu(BuildContext context) async {
78+
getOffset();
79+
await Navigator.push(
80+
context,
81+
PageRouteBuilder(
82+
transitionDuration: widget.duration ?? Duration(milliseconds: 100),
83+
pageBuilder: (context, animation, secondaryAnimation) {
84+
animation = Tween(begin: 0.0, end: 1.0).animate(animation);
85+
return FadeTransition(
86+
opacity: animation,
87+
child: FocusedMenuDetails(
88+
itemExtent: widget.menuItemExtent,
89+
menuBoxDecoration: widget.menuBoxDecoration,
90+
child: widget.child,
91+
childOffset: childOffset,
92+
childSize: childSize,
93+
menuItems: widget.menuItems,
94+
blurSize: widget.blurSize,
95+
menuWidth: widget.menuWidth,
96+
blurBackgroundColor: widget.blurBackgroundColor,
97+
animateMenu: widget.animateMenuItems ?? true,
98+
bottomOffsetHeight: widget.bottomOffsetHeight ?? 0,
99+
menuOffset: widget.menuOffset ?? 0,
100+
));
101+
},
102+
fullscreenDialog: true,
103+
opaque: false));
104+
}
92105
}
93106

94107
class FocusedMenuDetails extends StatelessWidget {
@@ -106,19 +119,7 @@ class FocusedMenuDetails extends StatelessWidget {
106119
final double menuOffset;
107120

108121
const FocusedMenuDetails(
109-
{Key key,
110-
@required this.menuItems,
111-
@required this.child,
112-
@required this.childOffset,
113-
@required this.childSize,
114-
@required this.menuBoxDecoration,
115-
@required this.itemExtent,
116-
@required this.animateMenu,
117-
@required this.blurSize,
118-
@required this.blurBackgroundColor,
119-
@required this.menuWidth,
120-
this.bottomOffsetHeight,
121-
this.menuOffset})
122+
{Key key, @required this.menuItems, @required this.child, @required this.childOffset, @required this.childSize,@required this.menuBoxDecoration, @required this.itemExtent,@required this.animateMenu,@required this.blurSize,@required this.blurBackgroundColor,@required this.menuWidth, this.bottomOffsetHeight, this.menuOffset})
122123
: super(key: key);
123124

124125
@override
@@ -128,15 +129,10 @@ class FocusedMenuDetails extends StatelessWidget {
128129
final maxMenuHeight = size.height * 0.45;
129130
final listHeight = menuItems.length * (itemExtent ?? 50.0);
130131

131-
final maxMenuWidth = menuWidth ?? (size.width * 0.70);
132+
final maxMenuWidth = menuWidth??(size.width * 0.70);
132133
final menuHeight = listHeight < maxMenuHeight ? listHeight : maxMenuHeight;
133-
final leftOffset = (childOffset.dx + maxMenuWidth) < size.width
134-
? childOffset.dx
135-
: (childOffset.dx - maxMenuWidth + childSize.width);
136-
final topOffset = (childOffset.dy + menuHeight + childSize.height) <
137-
size.height - bottomOffsetHeight
138-
? childOffset.dy + childSize.height + menuOffset
139-
: childOffset.dy - menuHeight - menuOffset;
134+
final leftOffset = (childOffset.dx+maxMenuWidth ) < size.width ? childOffset.dx: (childOffset.dx-maxMenuWidth+childSize.width);
135+
final topOffset = (childOffset.dy + menuHeight + childSize.height) < size.height - bottomOffsetHeight ? childOffset.dy + childSize.height + menuOffset : childOffset.dy - menuHeight - menuOffset;
140136
return Scaffold(
141137
backgroundColor: Colors.transparent,
142138
body: Container(
@@ -148,11 +144,9 @@ class FocusedMenuDetails extends StatelessWidget {
148144
Navigator.pop(context);
149145
},
150146
child: BackdropFilter(
151-
filter: ImageFilter.blur(
152-
sigmaX: blurSize ?? 4, sigmaY: blurSize ?? 4),
147+
filter: ImageFilter.blur(sigmaX: blurSize??4, sigmaY: blurSize??4),
153148
child: Container(
154-
color:
155-
(blurBackgroundColor ?? Colors.black).withOpacity(0.7),
149+
color: (blurBackgroundColor??Colors.black).withOpacity(0.7),
156150
),
157151
)),
158152
Positioned(
@@ -174,14 +168,8 @@ class FocusedMenuDetails extends StatelessWidget {
174168
decoration: menuBoxDecoration ??
175169
BoxDecoration(
176170
color: Colors.grey.shade200,
177-
borderRadius:
178-
const BorderRadius.all(Radius.circular(5.0)),
179-
boxShadow: [
180-
const BoxShadow(
181-
color: Colors.black38,
182-
blurRadius: 10,
183-
spreadRadius: 1)
184-
]),
171+
borderRadius: const BorderRadius.all(Radius.circular(5.0)),
172+
boxShadow: [const BoxShadow(color: Colors.black38, blurRadius: 10, spreadRadius: 1)]),
185173
child: ClipRRect(
186174
borderRadius: const BorderRadius.all(Radius.circular(5.0)),
187175
child: ListView.builder(
@@ -191,26 +179,24 @@ class FocusedMenuDetails extends StatelessWidget {
191179
itemBuilder: (context, index) {
192180
FocusedMenuItem item = menuItems[index];
193181
Widget listItem = GestureDetector(
194-
onTap: () {
182+
onTap:
183+
() {
195184
Navigator.pop(context);
196185
item.onPressed();
186+
197187
},
198188
child: Container(
199189
alignment: Alignment.center,
200190
margin: const EdgeInsets.only(bottom: 1),
201191
color: item.backgroundColor ?? Colors.white,
202192
height: itemExtent ?? 50.0,
203193
child: Padding(
204-
padding: const EdgeInsets.symmetric(
205-
vertical: 8.0, horizontal: 14),
194+
padding: const EdgeInsets.symmetric(vertical: 8.0, horizontal: 14),
206195
child: Row(
207-
mainAxisAlignment:
208-
MainAxisAlignment.spaceBetween,
196+
mainAxisAlignment: MainAxisAlignment.spaceBetween,
209197
children: <Widget>[
210198
item.title,
211-
if (item.trailingIcon != null) ...[
212-
item.trailingIcon
213-
]
199+
if (item.trailingIcon != null) ...[item.trailingIcon]
214200
],
215201
),
216202
)));
@@ -235,15 +221,10 @@ class FocusedMenuDetails extends StatelessWidget {
235221
),
236222
),
237223
),
238-
Positioned(
239-
top: childOffset.dy,
240-
left: childOffset.dx,
241-
child: AbsorbPointer(
242-
absorbing: true,
243-
child: Container(
244-
width: childSize.width,
245-
height: childSize.height,
246-
child: child))),
224+
Positioned(top: childOffset.dy, left: childOffset.dx, child: AbsorbPointer(absorbing: true, child: Container(
225+
width: childSize.width,
226+
height: childSize.height,
227+
child: child))),
247228
],
248229
),
249230
),

pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: focused_menu
22
description: This is an easy to implement package for adding Focused Long Press Menu to Flutter Applications
3-
version: 1.0.1
3+
version: 1.0.2
44
homepage: https://github.com/retroportalstudio/focused_menu.git
55

66
environment:

0 commit comments

Comments
 (0)