@@ -44,7 +44,8 @@ enum DropdownDirection {
44
44
downRight,
45
45
}
46
46
47
- typedef ContentBuilder = Widget Function (BuildContext context, VoidCallback repaint, VoidCallback close);
47
+ typedef ContentBuilder = Widget Function (
48
+ BuildContext context, VoidCallback repaint, VoidCallback close);
48
49
typedef ToggleBuilder = Widget Function (BuildContext context, bool isOpen);
49
50
50
51
/// A generic dropdown widget that enables arbitrary content
@@ -130,7 +131,10 @@ class _GenericDropdownState extends State<GenericDropdown> {
130
131
}
131
132
132
133
RenderBox ? _ancestor (BuildContext context) =>
133
- GenericDropdownConfigProvider .of (context)? .rootScreenKey? .currentContext? .findRenderObject () as RenderBox ? ;
134
+ GenericDropdownConfigProvider .of (context)
135
+ ? .rootScreenKey
136
+ ? .currentContext
137
+ ? .findRenderObject () as RenderBox ? ;
134
138
135
139
void _close () {
136
140
_overlayEntry? .remove ();
@@ -142,7 +146,8 @@ class _GenericDropdownState extends State<GenericDropdown> {
142
146
final renderBox = context.findRenderObject () as RenderBox ;
143
147
144
148
final size = renderBox.size;
145
- final togglePosition = renderBox.localToGlobal (Offset .zero, ancestor: _ancestor (context));
149
+ final togglePosition =
150
+ renderBox.localToGlobal (Offset .zero, ancestor: _ancestor (context));
146
151
147
152
final screenSize = _screenSize (context);
148
153
@@ -166,61 +171,93 @@ class _GenericDropdownState extends State<GenericDropdown> {
166
171
double ? top, left, bottom, right;
167
172
168
173
// Anchor TOP LEFT
169
- if (widget.anchor == DropdownAnchor .topLeft && widget.direction == DropdownDirection .upLeft) {
174
+ if (widget.anchor == DropdownAnchor .topLeft &&
175
+ widget.direction == DropdownDirection .upLeft) {
170
176
bottom = screenSize.height - togglePosition.dy + widget.offset.dy;
171
177
right = screenSize.width - togglePosition.dx + widget.offset.dx;
172
- } else if (widget.anchor == DropdownAnchor .topLeft && widget.direction == DropdownDirection .upRight) {
178
+ } else if (widget.anchor == DropdownAnchor .topLeft &&
179
+ widget.direction == DropdownDirection .upRight) {
173
180
bottom = screenSize.height - togglePosition.dy + widget.offset.dy;
174
181
left = togglePosition.dx + widget.offset.dx;
175
- } else if (widget.anchor == DropdownAnchor .topLeft && widget.direction == DropdownDirection .downLeft) {
182
+ } else if (widget.anchor == DropdownAnchor .topLeft &&
183
+ widget.direction == DropdownDirection .downLeft) {
176
184
top = togglePosition.dy + widget.offset.dy;
177
185
right = screenSize.width - togglePosition.dx + widget.offset.dx;
178
- } else if (widget.anchor == DropdownAnchor .topLeft && widget.direction == DropdownDirection .downRight) {
186
+ } else if (widget.anchor == DropdownAnchor .topLeft &&
187
+ widget.direction == DropdownDirection .downRight) {
179
188
top = togglePosition.dy + widget.offset.dy;
180
189
left = togglePosition.dx + widget.offset.dx;
181
190
}
182
191
183
192
// Anchor TOP RIGHT
184
- if (widget.anchor == DropdownAnchor .topRight && widget.direction == DropdownDirection .upLeft) {
193
+ if (widget.anchor == DropdownAnchor .topRight &&
194
+ widget.direction == DropdownDirection .upLeft) {
185
195
bottom = screenSize.height - togglePosition.dy + widget.offset.dy;
186
- right = screenSize.width - togglePosition.dx + widget.offset.dx - size.width;
187
- } else if (widget.anchor == DropdownAnchor .topRight && widget.direction == DropdownDirection .upRight) {
196
+ right =
197
+ screenSize.width - togglePosition.dx + widget.offset.dx - size.width;
198
+ } else if (widget.anchor == DropdownAnchor .topRight &&
199
+ widget.direction == DropdownDirection .upRight) {
188
200
bottom = screenSize.height - togglePosition.dy + widget.offset.dy;
189
201
left = togglePosition.dx + widget.offset.dx + size.width;
190
- } else if (widget.anchor == DropdownAnchor .topRight && widget.direction == DropdownDirection .downLeft) {
202
+ } else if (widget.anchor == DropdownAnchor .topRight &&
203
+ widget.direction == DropdownDirection .downLeft) {
191
204
top = togglePosition.dy + widget.offset.dy;
192
- right = screenSize.width - togglePosition.dx + widget.offset.dx - size.width;
193
- } else if (widget.anchor == DropdownAnchor .topRight && widget.direction == DropdownDirection .downRight) {
205
+ right =
206
+ screenSize.width - togglePosition.dx + widget.offset.dx - size.width;
207
+ } else if (widget.anchor == DropdownAnchor .topRight &&
208
+ widget.direction == DropdownDirection .downRight) {
194
209
top = togglePosition.dy + widget.offset.dy;
195
210
left = togglePosition.dx + widget.offset.dx + size.width;
196
211
}
197
212
198
213
// Anchor BOTTOM LEFT
199
- if (widget.anchor == DropdownAnchor .bottomLeft && widget.direction == DropdownDirection .upLeft) {
200
- bottom = screenSize.height - togglePosition.dy + widget.offset.dy - size.height;
214
+ if (widget.anchor == DropdownAnchor .bottomLeft &&
215
+ widget.direction == DropdownDirection .upLeft) {
216
+ bottom = screenSize.height -
217
+ togglePosition.dy +
218
+ widget.offset.dy -
219
+ size.height;
201
220
right = screenSize.width - togglePosition.dx + widget.offset.dx;
202
- } else if (widget.anchor == DropdownAnchor .bottomLeft && widget.direction == DropdownDirection .upRight) {
203
- bottom = screenSize.height - togglePosition.dy + widget.offset.dy - size.height;
221
+ } else if (widget.anchor == DropdownAnchor .bottomLeft &&
222
+ widget.direction == DropdownDirection .upRight) {
223
+ bottom = screenSize.height -
224
+ togglePosition.dy +
225
+ widget.offset.dy -
226
+ size.height;
204
227
left = togglePosition.dx + widget.offset.dx;
205
- } else if (widget.anchor == DropdownAnchor .bottomLeft && widget.direction == DropdownDirection .downLeft) {
228
+ } else if (widget.anchor == DropdownAnchor .bottomLeft &&
229
+ widget.direction == DropdownDirection .downLeft) {
206
230
top = togglePosition.dy + widget.offset.dy + size.height;
207
231
right = screenSize.width - togglePosition.dx + widget.offset.dx;
208
- } else if (widget.anchor == DropdownAnchor .bottomLeft && widget.direction == DropdownDirection .downRight) {
232
+ } else if (widget.anchor == DropdownAnchor .bottomLeft &&
233
+ widget.direction == DropdownDirection .downRight) {
209
234
top = togglePosition.dy + widget.offset.dy + size.height;
210
235
left = togglePosition.dx + widget.offset.dx;
211
236
}
212
237
213
238
// Anchor BOTTOM RIGHT
214
- if (widget.anchor == DropdownAnchor .bottomRight && widget.direction == DropdownDirection .upLeft) {
215
- bottom = screenSize.height - togglePosition.dy + widget.offset.dy - size.height;
216
- right = screenSize.width - togglePosition.dx + widget.offset.dx - size.width;
217
- } else if (widget.anchor == DropdownAnchor .bottomRight && widget.direction == DropdownDirection .upRight) {
218
- bottom = screenSize.height - togglePosition.dy + widget.offset.dy - size.height;
239
+ if (widget.anchor == DropdownAnchor .bottomRight &&
240
+ widget.direction == DropdownDirection .upLeft) {
241
+ bottom = screenSize.height -
242
+ togglePosition.dy +
243
+ widget.offset.dy -
244
+ size.height;
245
+ right =
246
+ screenSize.width - togglePosition.dx + widget.offset.dx - size.width;
247
+ } else if (widget.anchor == DropdownAnchor .bottomRight &&
248
+ widget.direction == DropdownDirection .upRight) {
249
+ bottom = screenSize.height -
250
+ togglePosition.dy +
251
+ widget.offset.dy -
252
+ size.height;
219
253
left = togglePosition.dx + widget.offset.dx + size.width;
220
- } else if (widget.anchor == DropdownAnchor .bottomRight && widget.direction == DropdownDirection .downLeft) {
254
+ } else if (widget.anchor == DropdownAnchor .bottomRight &&
255
+ widget.direction == DropdownDirection .downLeft) {
221
256
top = togglePosition.dy + widget.offset.dy + size.height;
222
- right = screenSize.width - togglePosition.dx + widget.offset.dx - size.width;
223
- } else if (widget.anchor == DropdownAnchor .bottomRight && widget.direction == DropdownDirection .downRight) {
257
+ right =
258
+ screenSize.width - togglePosition.dx + widget.offset.dx - size.width;
259
+ } else if (widget.anchor == DropdownAnchor .bottomRight &&
260
+ widget.direction == DropdownDirection .downRight) {
224
261
top = togglePosition.dy + widget.offset.dy + size.height;
225
262
left = togglePosition.dx + widget.offset.dx + size.width;
226
263
}
@@ -249,8 +286,8 @@ class _GenericDropdownState extends State<GenericDropdown> {
249
286
// content.
250
287
},
251
288
child: StatefulBuilder (
252
- builder: (context, setState) =>
253
- widget.contentBuilder .call (context, () => setState (() {}), _close)),
289
+ builder: (context, setState) => widget.contentBuilder
290
+ .call (context, () => setState (() {}), _close)),
254
291
),
255
292
),
256
293
],
@@ -265,7 +302,8 @@ class _GenericDropdownState extends State<GenericDropdown> {
265
302
setState (() => _isOpen = true );
266
303
}
267
304
268
- Size _screenSize (BuildContext context) => _ancestor (context)? .size ?? MediaQuery .of (context).size;
305
+ Size _screenSize (BuildContext context) =>
306
+ _ancestor (context)? .size ?? MediaQuery .of (context).size;
269
307
270
308
@override
271
309
Widget build (BuildContext context) => Row (
0 commit comments