Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow handling the handleTap event from a GlobalKey #304

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
18 changes: 10 additions & 8 deletions packages/dropdown_button2/lib/src/dropdown_button2.dart
Original file line number Diff line number Diff line change
Expand Up @@ -390,10 +390,11 @@ class DropdownButton2<T> extends StatefulWidget {
final bool _isFocused;

@override
State<DropdownButton2<T>> createState() => _DropdownButton2State<T>();
State<DropdownButton2<T>> createState() => DropdownButton2State<T>();
}

class _DropdownButton2State<T> extends State<DropdownButton2<T>>
/// The [State] for a [DropdownButton2].
class DropdownButton2State<T> extends State<DropdownButton2<T>>
with WidgetsBindingObserver {
int? _selectedIndex;
_DropdownRoute<T>? _dropdownRoute;
Expand Down Expand Up @@ -439,10 +440,10 @@ class _DropdownButton2State<T> extends State<DropdownButton2<T>>
}
_actionMap = <Type, Action<Intent>>{
ActivateIntent: CallbackAction<ActivateIntent>(
onInvoke: (ActivateIntent intent) => _handleTap(),
onInvoke: (ActivateIntent intent) => handleTap(),
),
ButtonActivateIntent: CallbackAction<ButtonActivateIntent>(
onInvoke: (ButtonActivateIntent intent) => _handleTap(),
onInvoke: (ButtonActivateIntent intent) => handleTap(),
),
};
}
Expand Down Expand Up @@ -525,7 +526,7 @@ class _DropdownButton2State<T> extends State<DropdownButton2<T>>

void _programmaticallyOpenDropdown() {
if (_enabled && !_isMenuOpen.value) {
_handleTap();
handleTap();
}
}

Expand Down Expand Up @@ -562,7 +563,8 @@ class _DropdownButton2State<T> extends State<DropdownButton2<T>>
.add(_dropdownStyle.scrollPadding ?? EdgeInsets.zero);
}

void _handleTap() {
/// allow handling tap event for public state
void handleTap() {
final NavigatorState navigator = Navigator.of(context,
rootNavigator:
_dropdownStyle.isFullScreen ?? _dropdownStyle.useRootNavigator);
Expand Down Expand Up @@ -874,8 +876,8 @@ class _DropdownButton2State<T> extends State<DropdownButton2<T>>
actions: _actionMap,
child: InkWell(
mouseCursor: effectiveMouseCursor,
onTap: _enabled && !widget.openWithLongPress ? _handleTap : null,
onLongPress: _enabled && widget.openWithLongPress ? _handleTap : null,
onTap: _enabled && !widget.openWithLongPress ? handleTap : null,
onLongPress: _enabled && widget.openWithLongPress ? handleTap : null,
canRequestFocus: _enabled,
focusNode: _focusNode,
autofocus: widget.autofocus,
Expand Down