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;
|
Orientation? _lastOrientation;
|
||||||
FocusNode? _internalNode;
|
FocusNode? _internalNode;
|
||||||
FocusNode? get focusNode => widget.focusNode ?? _internalNode;
|
FocusNode? get focusNode => widget.focusNode ?? _internalNode;
|
||||||
bool _hasPrimaryFocus = false;
|
|
||||||
late Map<Type, Action<Intent>> _actionMap;
|
late Map<Type, Action<Intent>> _actionMap;
|
||||||
|
|
||||||
// Only used if needed to create _internalNode.
|
// Only used if needed to create _internalNode.
|
||||||
@ -1244,14 +1243,12 @@ class _DropdownButtonState<T> extends State<DropdownButton<T>> with WidgetsBindi
|
|||||||
onInvoke: (ButtonActivateIntent intent) => _handleTap(),
|
onInvoke: (ButtonActivateIntent intent) => _handleTap(),
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
focusNode!.addListener(_handleFocusChanged);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
WidgetsBinding.instance.removeObserver(this);
|
WidgetsBinding.instance.removeObserver(this);
|
||||||
_removeDropdownRoute();
|
_removeDropdownRoute();
|
||||||
focusNode!.removeListener(_handleFocusChanged);
|
|
||||||
_internalNode?.dispose();
|
_internalNode?.dispose();
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
@ -1262,25 +1259,11 @@ class _DropdownButtonState<T> extends State<DropdownButton<T>> with WidgetsBindi
|
|||||||
_lastOrientation = null;
|
_lastOrientation = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
void _handleFocusChanged() {
|
|
||||||
if (_hasPrimaryFocus != focusNode!.hasPrimaryFocus) {
|
|
||||||
setState(() {
|
|
||||||
_hasPrimaryFocus = focusNode!.hasPrimaryFocus;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void didUpdateWidget(DropdownButton<T> oldWidget) {
|
void didUpdateWidget(DropdownButton<T> oldWidget) {
|
||||||
super.didUpdateWidget(oldWidget);
|
super.didUpdateWidget(oldWidget);
|
||||||
if (widget.focusNode != oldWidget.focusNode) {
|
if (widget.focusNode == null) {
|
||||||
oldWidget.focusNode?.removeListener(_handleFocusChanged);
|
_internalNode ??= _createFocusNode();
|
||||||
if (widget.focusNode == null) {
|
|
||||||
_internalNode ??= _createFocusNode();
|
|
||||||
}
|
|
||||||
_hasPrimaryFocus = focusNode!.hasPrimaryFocus;
|
|
||||||
focusNode!.addListener(_handleFocusChanged);
|
|
||||||
}
|
}
|
||||||
_updateSelectedIndex();
|
_updateSelectedIndex();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user