Skip to content

Commit

Permalink
This is working now
Browse files Browse the repository at this point in the history
  • Loading branch information
jonas-martinez committed Apr 11, 2024
1 parent 829df4f commit 8f290b0
Showing 1 changed file with 19 additions and 22 deletions.
41 changes: 19 additions & 22 deletions lib/component/lenra_dropdown_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -88,27 +88,25 @@ class _LenraDropdownButtonState extends State<LenraDropdownButton> {
final LayerLink _layerLink = LayerLink();
final OverlayPortalController _overlayPortalController = OverlayPortalController();
final GlobalKey _buttonKey = GlobalKey();
final GlobalKey _overlayKey = GlobalKey();
bool showOverlay = false;

@override
Widget build(BuildContext context) {
return CompositedTransformTarget(
link: _layerLink,
child: OverlayPortal(
controller: _overlayPortalController,
overlayChildBuilder: (context) {
return GestureDetector(
behavior: HitTestBehavior.translucent,
onTap: () => _overlayPortalController.toggle(),
child: _Dropdown(
key: _overlayKey,
child: widget.child,
layerLink: _layerLink,
buttonKey: _buttonKey,
),
);
},
return OverlayPortal(
controller: _overlayPortalController,
overlayChildBuilder: (context) {
return GestureDetector(
behavior: HitTestBehavior.translucent,
onTap: () => _overlayPortalController.toggle(),
child: _Dropdown(
child: widget.child,
layerLink: _layerLink,
buttonKey: _buttonKey,
),
);
},
child: CompositedTransformTarget(
link: _layerLink,
child: LenraButton(
key: _buttonKey,
text: widget.text,
Expand Down Expand Up @@ -143,6 +141,7 @@ class _Dropdown extends StatefulWidget {

class _DropdownState extends State<_Dropdown> with TickerProviderStateMixin {
// TickerProviderStateMixin is used to correctly execute the fade animation of the menu
GlobalKey overlayKey = GlobalKey();
Offset? overlayOffset;
bool verticalScroll = false;
bool horizontalScroll = false;
Expand All @@ -161,9 +160,7 @@ class _DropdownState extends State<_Dropdown> with TickerProviderStateMixin {

WidgetsBinding.instance.addPostFrameCallback((_) {
if (overlayOffset == null) {
// How to get the overlay context ????????
var overlay = context.findRenderObject();

var overlay = overlayKey.currentContext?.findRenderObject();

if (overlay != null) {
_updateOverlayOffset(overlay);
Expand Down Expand Up @@ -240,14 +237,14 @@ class _DropdownState extends State<_Dropdown> with TickerProviderStateMixin {
Widget _forceTakeWidth(Widget child) {
return SizedBox(
width: double.infinity,
child: child,
child: Container(key: overlayKey, child: child),
);
}

Widget _addMinWidth(Widget child) {
return ConstrainedBox(
constraints: BoxConstraints(minWidth: buttonSize.width),
child: child,
child: Container(key: overlayKey, child: child),
);
}

Expand Down

0 comments on commit 8f290b0

Please sign in to comment.