Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 20 additions & 13 deletions packages/komodo_ui_kit/lib/src/buttons/ui_dropdown.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class UiDropdown extends StatefulWidget {
}

class _UiDropdownState extends State<UiDropdown> with WidgetsBindingObserver {
late OverlayEntry _tooltipWrapper;
OverlayEntry? _tooltipWrapper;
GlobalKey _switcherKey = GlobalKey();
Size? _switcherSize;
Offset? _switcherOffset;
Expand All @@ -43,18 +43,18 @@ class _UiDropdownState extends State<UiDropdown> with WidgetsBindingObserver {
_switcherOffset = renderObject.localToGlobal(Offset.zero);
}
_tooltipWrapper = _buildTooltipWrapper();

if (widget.isOpen) _open();
});

if (widget.isOpen) _open();

super.initState();
}

@override
void didUpdateWidget(covariant UiDropdown oldWidget) {
if (widget.isOpen == oldWidget.isOpen) return;

if (widget.isOpen != _tooltipWrapper.mounted) _switch();
if (widget.isOpen != (_tooltipWrapper?.mounted ?? false)) _switch();
super.didUpdateWidget(oldWidget);
}

Expand All @@ -68,14 +68,17 @@ class _UiDropdownState extends State<UiDropdown> with WidgetsBindingObserver {
_switcherOffset = renderObject.localToGlobal(Offset.zero);
});
}
if (_tooltipWrapper?.mounted == true) {
_close();
}
Comment thread
CharlVS marked this conversation as resolved.
_tooltipWrapper = _buildTooltipWrapper();
}

@override
void dispose() {
WidgetsBinding.instance.removeObserver(this);
if (_tooltipWrapper.mounted) {
_tooltipWrapper.remove();
if (_tooltipWrapper?.mounted == true) {
_tooltipWrapper!.remove();
}
super.dispose();
}
Expand Down Expand Up @@ -126,23 +129,27 @@ class _UiDropdownState extends State<UiDropdown> with WidgetsBindingObserver {
}

void _switch() {
if (_tooltipWrapper.mounted) {
if (_tooltipWrapper?.mounted == true) {
_close();
} else {
_open();
}
}

void _open() {
Overlay.of(context).insert(_tooltipWrapper);
final onSwitch = widget.onSwitch;
if (onSwitch != null) onSwitch(true);
if (_tooltipWrapper != null) {
Overlay.of(context).insert(_tooltipWrapper!);
final onSwitch = widget.onSwitch;
if (onSwitch != null) onSwitch(true);
}
}

void _close() {
_tooltipWrapper.remove();
final onSwitch = widget.onSwitch;
if (onSwitch != null) onSwitch(false);
if (_tooltipWrapper != null) {
_tooltipWrapper!.remove();
final onSwitch = widget.onSwitch;
if (onSwitch != null) onSwitch(false);
}
}

double? get _top {
Expand Down
Loading