Unverified Commit 042c0366 authored by Ahmed Elsayed's avatar Ahmed Elsayed Committed by GitHub

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
parent 32fde139
......@@ -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();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment