@@ -13,6 +13,9 @@ Easy and Fast Way to build Context Menus
13
13
![ GitHub stars] ( https://img.shields.io/github/stars/alnitak/flutter_star_menu?style=flat-square )
14
14
![ GitHub license] ( https://img.shields.io/github/license/alnitak/flutter_star_menu?style=flat-square )
15
15
16
+ ![ Image] ( https://github.com/alnitak/flutter_star_menu/blob/master/images/dont_buy_me_coffe.png )
17
+ Instead, a star would be wonderful! ;)
18
+
16
19
A simple way to attach a popup menu to any widget with any widget as menu entries.
17
20
Menu entry widgets can bind a sub-menu with different shapes.
18
21
Multiple ways to fine-tune animation and position.
@@ -39,7 +42,7 @@ Using the package is pretty simple:
39
42
- install the package with ` flutter pub add star_menu `
40
43
- feed the ` items ` parameter with the menu entry widgets list
41
44
- set the ` params ` with ` StarMenuParameters `
42
- - set the ` child ` with a widget you like to press to open the menu
45
+ - set the ` child ` with a widget you wish to press to open the menu
43
46
44
47
``` dart
45
48
StarMenu(
@@ -100,36 +103,108 @@ FloatingActionButton(
100
103
onPressed: () {print('FloatingActionButton tapped');},
101
104
child: Icon(Icons.looks_one),
102
105
).addStarMenu(
103
- context,
104
- entries,
106
+ items,
105
107
StarMenuParameters(),
108
+ controller,
106
109
onItemTapped: (index, controller) {}),
107
110
```
111
+ <br />
112
+ <br />
113
+
114
+ ## *** Programmatically open menu***
115
+ There are two ways to programmatically open a menu, for example when pressing a button:
116
+
117
+ - ** if you already have a StarMenu in the tree, add [ StarMenuController] to it:**
118
+ ``` dart
119
+ StarMenuController starMenuController = StarMenuController();
120
+
121
+ StarMenu(
122
+ params: StarMenuParameters(),
123
+ controller: starMenuController,
124
+ items: entries,
125
+ child: ...,
126
+ )
127
+ ```
128
+ then in your button:
129
+ ``` dart
130
+ ElevatedButton(
131
+ onPressed: () => starMenuController.openMenu!(),
132
+ child: ...,
133
+ ),
134
+ ```
108
135
109
- ### StarMenuParameters
136
+ - ** if you want to dinamically create a StartMenu for another widget, assign a GlobalKey to your widget:**
137
+ ``` dart
138
+ GlobalKey containerKey = GlobalKey();
139
+ ...
140
+ Container(
141
+ key: containerKey,
142
+ width: 40,
143
+ height: 40,
144
+ ),
145
+ ```
146
+ then in your button call * StarMenuOverlay.displayStarMenu* with the widget context:
147
+ ``` dart
148
+ ElevatedButton(
149
+ onPressed: () {
150
+ StarMenuOverlay.displayStarMenu(
151
+ containerKey.currentContext!,
152
+ StarMenu(
153
+ params: StarMenuParameters(),
154
+ items: entries,
155
+ parentContext: containerKey.currentContext,
156
+ ),
157
+ );
158
+ },
159
+ child: ...
160
+ ),
161
+ ```
110
162
163
+ <br />
164
+ <br />
165
+
166
+ ### *** StarMenu***
167
+ Only [ items] or [ lazyItems] can be passed, not both.
168
+ | Name| Type| Defaults| Description|
169
+ | :-------| :----------| :----------| :-----------|
170
+ | *** params*** | class| StarMenuParameters| See below.|
171
+ | *** items*** | List<Widget >?| -| Widget items entry list.|
172
+ | *** lazyItems*** | Future<List<Widget >> Function()?| -| Function to build dynamically items list whenever the menu open occurs.|
173
+ | *** child*** | Widget| -| Widget that triggers the opening of the menu. Only [ child] or [ parentContext] is allowed|
174
+ | *** parentContext*** | BuildContext| -| Widget that triggers the opening of the menu. Only [ child] or [ parentContext] is allowed|
175
+ | *** controller*** | StarMenuController| -| context of the Widget where the menu will be opened. Only [ child] or [ parentContext] is allowed|
176
+ | *** onStateChanged*** | Function(MenuState state)?| -| Return current menu state.|
177
+
178
+ <br />
179
+ <br />
180
+
181
+ ### *** StarMenuParameters***
111
182
Class to define all the parameters for the shape, animation and menu behavior.
112
183
113
184
| Name| Type| Defaults| Description|
114
185
| :-------| :----------| :----------| :-----------|
115
- | * shape* | enum| MenuShape.circle| Menu shape kind. Could be [ MenuShape.circle] , [ MenuShape.linear] , [ MenuShape.grid] .|
116
- | * boundaryBackground* | class| -| See below.|
117
- | * linearShapeParams* | class| -| See below.|
118
- | * circleShapeParams* | class| -| See below.|
119
- | * gridShapeParams* | class| -| See below.|
120
- | * backgroundParams* | class| -| See below.|
121
- | * openDurationMs* | int| 400| Open animation duration ms.|
122
- | * closeDurationMs* | int| 150| Close animation duration ms.|
123
- | * rotateItemsAnimationAngle* | double| 0.0| Starting rotation angle of the items that will reach 0 DEG when animation ends.|
124
- | * startItemScaleAnimation* | double| 0.3| Starting scale of the items that will reach 1 when animation ends.|
125
- | * centerOffset* | Offset| Offset.zero| Shift offset of menu center from the center of parent widget.|
126
- | * useScreenCenter* | bool| false| Use the screen center instead of parent widget center.|
127
- | * checkItemsScreenBoundaries* | bool| false| Checks if the whole menu boundaries exceed screen edges, if so set it in place to be all visible.|
128
- | * checkMenuScreenBoundaries* | bool| true| Checks if items exceed screen edges, if so set them in place to be visible.|
129
- | * animationCurve* | Curve| Curves.fastOutSlowIn| Animation curve kind to use.|
130
- | * useLongPress* | bool| false| Use long press instead of a tap to open the menu.|
131
- | * longPressDuration* | Duration| 500 ms| The timing to trigger long press.|
132
- | * onHoverScale* | double| 1.0| Scale item when mouse is hover (desktop only)|
186
+ | *** shape*** | enum| MenuShape.circle| Menu shape kind. Could be [ MenuShape.circle] , [ MenuShape.linear] , [ MenuShape.grid] .|
187
+ | *** boundaryBackground*** | class| -| See below.|
188
+ | *** linearShapeParams*** | class| -| See below.|
189
+ | *** circleShapeParams*** | class| -| See below.|
190
+ | *** gridShapeParams*** | class| -| See below.|
191
+ | *** backgroundParams*** | class| -| See below.|
192
+ | *** openDurationMs*** | int| 400| Open animation duration ms.|
193
+ | *** closeDurationMs*** | int| 150| Close animation duration ms.|
194
+ | *** rotateItemsAnimationAngle*** | double| 0.0| Starting rotation angle of the items that will reach 0 DEG when animation ends.|
195
+ | *** startItemScaleAnimation*** | double| 0.3| Starting scale of the items that will reach 1 when animation ends.|
196
+ | *** centerOffset*** | Offset| Offset.zero| Shift offset of menu center from the center of parent widget.|
197
+ | *** useScreenCenter*** | bool| false| Use the screen center instead of parent widget center.|
198
+ | *** useTouchAsCenter*** | bool| false| Use the touch coordinate as the menu center.|
199
+ | *** checkItemsScreenBoundaries*** | bool| false| Checks if the whole menu boundaries exceed screen edges, if so set it in place to be all visible.|
200
+ | *** checkMenuScreenBoundaries*** | bool| true| Checks if items exceed screen edges, if so set them in place to be visible.|
201
+ | *** animationCurve*** | Curve| Curves.fastOutSlowIn| Animation curve kind to use.|
202
+ | *** useLongPress*** | bool| false| Use long press instead of a tap to open the menu.|
203
+ | *** longPressDuration*** | Duration| 500 ms| The timing to trigger long press.|
204
+ | *** onHoverScale*** | double| 1.0| Scale item when mouse is hover (desktop only)|
205
+
206
+ <br />
207
+ <br />
133
208
134
209
There are some *** StarMenuParameters*** factory presets with which you can set * StarMenu.params*
135
210
@@ -154,54 +229,64 @@ There are some ***StarMenuParameters*** factory presets with which you can set *
154
229
155
230
156
231
---
232
+ <br />
233
+ <br />
157
234
158
- ### BoundaryBackground
235
+ ### *** BoundaryBackground***
159
236
160
237
| Name| Type| Defaults| Description|
161
238
| :-------| :----------| :----------| :-----------|
162
- | * color* | Color| 0x80000000| color of the boundary background.|
163
- | * padding* | EdgeInsets| EdgeInsets.all(8.0)| Padding of the boundary background.|
164
- | * decoration* | Decoration| BorderRadius.circular(8)| background Container widget decoration.|
239
+ | *** color** *| Color| 0x80000000| color of the boundary background.|
240
+ | *** padding** *| EdgeInsets| EdgeInsets.all(8.0)| Padding of the boundary background.|
241
+ | *** decoration** *| Decoration| BorderRadius.circular(8)| background Container widget decoration.|
165
242
166
243
---
244
+ <br />
245
+ <br />
167
246
168
- ### LinearShapeParams
247
+ ### *** LinearShapeParams***
169
248
170
249
| Name| Type| Defaults| Description|
171
250
| :-------| :----------| :----------| :-----------|
172
- | * angle* | double| 90.0| Degree angle. Anticlockwise with 0° on 3 o'clock.|
173
- | * space* | double| 0.0| Space between items.|
174
- | * alignment* | LinearAlignment| center| * left* , * center* , * right* , * top* , * bottom* . Useful when the linear shape is vertical or horizontal.|
251
+ | *** angle** *| double| 90.0| Degree angle. Anticlockwise with 0° on 3 o'clock.|
252
+ | *** space** *| double| 0.0| Space between items.|
253
+ | *** alignment** *| LinearAlignment| center| * left* , * center* , * right* , * top* , * bottom* . Useful when the linear shape is vertical or horizontal.|
175
254
176
255
---
256
+ <br />
257
+ <br />
177
258
178
- ### CircleShapeParams
259
+ ### *** CircleShapeParams***
179
260
180
261
| Name| Type| Defaults| Description|
181
262
| :-------| :----------| :----------| :-----------|
182
- | * radiusX* | double| 100.0| Horizontal radius.|
183
- | * radiusY* | double| 100.0| Vertical radius.|
184
- | * startAngle* | double| 0.0| Starting angle for the 1st item. Anticlockwise with 0° on the right.|
185
- | * endAngle* | double| 360.0| Ending angle for the 1st item. Anticlockwise with 0° on the right.|
263
+ | *** radiusX** *| double| 100.0| Horizontal radius.|
264
+ | *** radiusY** *| double| 100.0| Vertical radius.|
265
+ | *** startAngle** *| double| 0.0| Starting angle for the 1st item. Anticlockwise with 0° on the right.|
266
+ | *** endAngle** *| double| 360.0| Ending angle for the 1st item. Anticlockwise with 0° on the right.|
186
267
187
268
---
269
+ <br />
270
+ <br />
188
271
189
- ### GridShapeParams
272
+ ### *** GridShapeParams***
190
273
191
274
| Name| Type| Defaults| Description|
192
275
| :-------| :----------| :----------| :-----------|
193
- | * columns* | int| 3| Number of columns.|
194
- | * columnsSpaceH* | int| 0| Horizontal space between items.|
195
- | * columnsSpaceV* | int| 0| Vertical space between items.|
276
+ | *** columns** *| int| 3| Number of columns.|
277
+ | *** columnsSpaceH** *| int| 0| Horizontal space between items.|
278
+ | *** columnsSpaceV** *| int| 0| Vertical space between items.|
196
279
197
280
---
281
+ <br />
282
+ <br />
198
283
199
- ### BackgroundParams
284
+ ### *** BackgroundParams***
200
285
201
286
| Name| Type| Defaults| Description|
202
287
| :-------| :----------| :----------| :-----------|
203
- | * animatedBlur* | bool| false| Animate background blur from 0.0 to sigma if true.|
204
- | * sigmaX* | double| 0.0| Horizontal blur.|
205
- | * sigmaY* | double| 0.0| Vertical blur.|
206
- | * animatedBackgroundColor* | bool| false| Animate [ backgroundColor ] from transparent if true .|
207
- | * backgroundColor* | Color| # 80000000 | Background color.|
288
+ | *** animatedBlur** *| bool| false| Animate background blur from 0.0 to sigma if true.|
289
+ | *** sigmaX** *| double| 0.0| Horizontal blur.|
290
+ | *** sigmaY** *| double| 0.0| Vertical blur.|
291
+ | *** animatedBackgroundColor*** | bool| false| If true animate from transparent to [ backgroundColor ] .|
292
+ | *** backgroundColor*** | Color| Colors.transparent | Background color.|
0 commit comments