Skip to content
Open
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
22 changes: 19 additions & 3 deletions lib/src/widget/raw.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ class _RawFlexDropDownState extends State<RawFlexDropDown> {
/// width of the button after the widget rendered
double? _buttonWidth;

/// to handle if we click outside the dropdown
bool _justClosedViaOutside = false;

@override
Widget build(BuildContext context) {
final direction = Directionality.of(context);
Expand All @@ -63,6 +66,7 @@ class _RawFlexDropDownState extends State<RawFlexDropDown> {
log('dismissOnTapOutside');
menu = TapRegion(
onTapOutside: (event) {
_justClosedViaOutside = true;
widget.controller.hide();
},
child: menu,
Expand Down Expand Up @@ -127,8 +131,20 @@ class _RawFlexDropDownState extends State<RawFlexDropDown> {
}

void onTap() {
_buttonWidth = context.size?.width;

widget.controller.toggle();
/// If the dropdown is already showing, hide it
if (widget.controller.isShowing) {
widget.controller.hide();
} else {
// Else, check if we just closed it via outside tap
if (_justClosedViaOutside) {
// Reset the flag and bail out.
_justClosedViaOutside = false;
return;
}

// Otherwise, show it
_buttonWidth = context.size?.width;
widget.controller.show();
}
}
}