mirror of
https://github.com/flutter/flutter
synced 2024-08-27 12:00:58 +00:00
Remove unnecessary variable _hasPrimaryFocus
(#129066)
`_hasPrimaryFocus` variable and its related code is no longer needed after using `InkWell` for `DropdownButton` at https://github.com/flutter/flutter/pull/95906
This commit is contained in:
parent
32fde139bc
commit
042c0366c9
|
@ -1221,7 +1221,6 @@ class _DropdownButtonState<T> extends State<DropdownButton<T>> with WidgetsBindi
|
|||
Orientation? _lastOrientation;
|
||||
FocusNode? _internalNode;
|
||||
FocusNode? get focusNode => widget.focusNode ?? _internalNode;
|
||||
bool _hasPrimaryFocus = false;
|
||||
late Map<Type, Action<Intent>> _actionMap;
|
||||
|
||||
// Only used if needed to create _internalNode.
|
||||
|
@ -1244,14 +1243,12 @@ class _DropdownButtonState<T> extends State<DropdownButton<T>> with WidgetsBindi
|
|||
onInvoke: (ButtonActivateIntent intent) => _handleTap(),
|
||||
),
|
||||
};
|
||||
focusNode!.addListener(_handleFocusChanged);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
WidgetsBinding.instance.removeObserver(this);
|
||||
_removeDropdownRoute();
|
||||
focusNode!.removeListener(_handleFocusChanged);
|
||||
_internalNode?.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
@ -1262,25 +1259,11 @@ class _DropdownButtonState<T> extends State<DropdownButton<T>> with WidgetsBindi
|
|||
_lastOrientation = null;
|
||||
}
|
||||
|
||||
void _handleFocusChanged() {
|
||||
if (_hasPrimaryFocus != focusNode!.hasPrimaryFocus) {
|
||||
setState(() {
|
||||
_hasPrimaryFocus = focusNode!.hasPrimaryFocus;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
void didUpdateWidget(DropdownButton<T> oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
if (widget.focusNode != oldWidget.focusNode) {
|
||||
oldWidget.focusNode?.removeListener(_handleFocusChanged);
|
||||
if (widget.focusNode == null) {
|
||||
_internalNode ??= _createFocusNode();
|
||||
}
|
||||
_hasPrimaryFocus = focusNode!.hasPrimaryFocus;
|
||||
focusNode!.addListener(_handleFocusChanged);
|
||||
if (widget.focusNode == null) {
|
||||
_internalNode ??= _createFocusNode();
|
||||
}
|
||||
_updateSelectedIndex();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue