Revert "Replace TextField.canRequestFocus with TextField.focusNode.canRequestFocus" (#132104)
Reverts flutter/flutter#130164 reverting because it cause internal google testing failures b/294917394
This commit is contained in:
parent
915c52453b
commit
cef00d0c53
@ -4,7 +4,6 @@
|
|||||||
|
|
||||||
import 'dart:math' as math;
|
import 'dart:math' as math;
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:flutter/rendering.dart';
|
import 'package:flutter/rendering.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:flutter/widgets.dart';
|
import 'package:flutter/widgets.dart';
|
||||||
@ -310,7 +309,6 @@ class _DropdownMenuState<T> extends State<DropdownMenu<T>> {
|
|||||||
int? currentHighlight;
|
int? currentHighlight;
|
||||||
double? leadingPadding;
|
double? leadingPadding;
|
||||||
bool _menuHasEnabledItem = false;
|
bool _menuHasEnabledItem = false;
|
||||||
late final FocusNode _focusNode;
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
@ -328,18 +326,6 @@ class _DropdownMenuState<T> extends State<DropdownMenu<T>> {
|
|||||||
TextSelection.collapsed(offset: _textEditingController.text.length);
|
TextSelection.collapsed(offset: _textEditingController.text.length);
|
||||||
}
|
}
|
||||||
refreshLeadingPadding();
|
refreshLeadingPadding();
|
||||||
_focusNode = FocusNode(
|
|
||||||
canRequestFocus: canRequestFocus(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
void didChangeDependencies() {
|
|
||||||
super.didChangeDependencies();
|
|
||||||
final bool widgetCanRequestFocus = canRequestFocus();
|
|
||||||
if (widgetCanRequestFocus != _focusNode.canRequestFocus) {
|
|
||||||
_focusNode.canRequestFocus = widgetCanRequestFocus;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -367,10 +353,6 @@ class _DropdownMenuState<T> extends State<DropdownMenu<T>> {
|
|||||||
TextSelection.collapsed(offset: _textEditingController.text.length);
|
TextSelection.collapsed(offset: _textEditingController.text.length);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
final bool widgetCanRequestFocus = canRequestFocus();
|
|
||||||
if (widgetCanRequestFocus != _focusNode.canRequestFocus) {
|
|
||||||
_focusNode.canRequestFocus = widgetCanRequestFocus;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool canRequestFocus() {
|
bool canRequestFocus() {
|
||||||
@ -378,7 +360,7 @@ class _DropdownMenuState<T> extends State<DropdownMenu<T>> {
|
|||||||
return widget.requestFocusOnTap!;
|
return widget.requestFocusOnTap!;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (defaultTargetPlatform) {
|
switch (Theme.of(context).platform) {
|
||||||
case TargetPlatform.iOS:
|
case TargetPlatform.iOS:
|
||||||
case TargetPlatform.android:
|
case TargetPlatform.android:
|
||||||
case TargetPlatform.fuchsia:
|
case TargetPlatform.fuchsia:
|
||||||
@ -610,8 +592,7 @@ class _DropdownMenuState<T> extends State<DropdownMenu<T>> {
|
|||||||
final Widget textField = TextField(
|
final Widget textField = TextField(
|
||||||
key: _anchorKey,
|
key: _anchorKey,
|
||||||
mouseCursor: effectiveMouseCursor,
|
mouseCursor: effectiveMouseCursor,
|
||||||
focusNode: _focusNode,
|
canRequestFocus: canRequestFocus(),
|
||||||
readOnly: !canRequestFocus(),
|
|
||||||
enableInteractiveSelection: canRequestFocus(),
|
enableInteractiveSelection: canRequestFocus(),
|
||||||
textAlignVertical: TextAlignVertical.center,
|
textAlignVertical: TextAlignVertical.center,
|
||||||
style: effectiveTextStyle,
|
style: effectiveTextStyle,
|
||||||
|
@ -314,10 +314,6 @@ class TextField extends StatefulWidget {
|
|||||||
this.scribbleEnabled = true,
|
this.scribbleEnabled = true,
|
||||||
this.enableIMEPersonalizedLearning = true,
|
this.enableIMEPersonalizedLearning = true,
|
||||||
this.contextMenuBuilder = _defaultContextMenuBuilder,
|
this.contextMenuBuilder = _defaultContextMenuBuilder,
|
||||||
@Deprecated(
|
|
||||||
'Use `focusNode` instead. '
|
|
||||||
'This feature was deprecated after v3.12.0-14.0.pre.',
|
|
||||||
)
|
|
||||||
this.canRequestFocus = true,
|
this.canRequestFocus = true,
|
||||||
this.spellCheckConfiguration,
|
this.spellCheckConfiguration,
|
||||||
this.magnifierConfiguration,
|
this.magnifierConfiguration,
|
||||||
@ -780,10 +776,6 @@ class TextField extends StatefulWidget {
|
|||||||
/// Defaults to true. If false, the text field will not request focus
|
/// Defaults to true. If false, the text field will not request focus
|
||||||
/// when tapped, or when its context menu is displayed. If false it will not
|
/// when tapped, or when its context menu is displayed. If false it will not
|
||||||
/// be possible to move the focus to the text field with tab key.
|
/// be possible to move the focus to the text field with tab key.
|
||||||
@Deprecated(
|
|
||||||
'Use `focusNode` instead. '
|
|
||||||
'This feature was deprecated after v3.12.0-14.0.pre.',
|
|
||||||
)
|
|
||||||
final bool canRequestFocus;
|
final bool canRequestFocus;
|
||||||
|
|
||||||
/// {@macro flutter.widgets.undoHistory.controller}
|
/// {@macro flutter.widgets.undoHistory.controller}
|
||||||
@ -1034,9 +1026,7 @@ class _TextFieldState extends State<TextField> with RestorationMixin implements
|
|||||||
if (widget.controller == null) {
|
if (widget.controller == null) {
|
||||||
_createLocalController();
|
_createLocalController();
|
||||||
}
|
}
|
||||||
_effectiveFocusNode.canRequestFocus = widget.focusNode == null
|
_effectiveFocusNode.canRequestFocus = widget.canRequestFocus && _isEnabled;
|
||||||
? widget.canRequestFocus && _isEnabled
|
|
||||||
: widget.focusNode!.canRequestFocus && _isEnabled;
|
|
||||||
_effectiveFocusNode.addListener(_handleFocusChanged);
|
_effectiveFocusNode.addListener(_handleFocusChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1044,9 +1034,7 @@ class _TextFieldState extends State<TextField> with RestorationMixin implements
|
|||||||
final NavigationMode mode = MediaQuery.maybeNavigationModeOf(context) ?? NavigationMode.traditional;
|
final NavigationMode mode = MediaQuery.maybeNavigationModeOf(context) ?? NavigationMode.traditional;
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
case NavigationMode.traditional:
|
case NavigationMode.traditional:
|
||||||
return widget.focusNode == null
|
return widget.canRequestFocus && _isEnabled;
|
||||||
? widget.canRequestFocus && _isEnabled
|
|
||||||
: widget.focusNode!.canRequestFocus && _isEnabled;
|
|
||||||
case NavigationMode.directional:
|
case NavigationMode.directional:
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -1232,7 +1232,7 @@ void main() {
|
|||||||
|
|
||||||
final Finder textFieldFinder = find.byType(TextField);
|
final Finder textFieldFinder = find.byType(TextField);
|
||||||
final TextField result = tester.widget<TextField>(textFieldFinder);
|
final TextField result = tester.widget<TextField>(textFieldFinder);
|
||||||
expect(result.focusNode!.canRequestFocus, false);
|
expect(result.canRequestFocus, false);
|
||||||
}, variant: TargetPlatformVariant.mobile());
|
}, variant: TargetPlatformVariant.mobile());
|
||||||
|
|
||||||
testWidgets('The text input field should be focused on desktop platforms '
|
testWidgets('The text input field should be focused on desktop platforms '
|
||||||
@ -1300,7 +1300,7 @@ void main() {
|
|||||||
|
|
||||||
final Finder textFieldFinder1 = find.byType(TextField);
|
final Finder textFieldFinder1 = find.byType(TextField);
|
||||||
final TextField textField1 = tester.widget<TextField>(textFieldFinder1);
|
final TextField textField1 = tester.widget<TextField>(textFieldFinder1);
|
||||||
expect(textField1.focusNode!.canRequestFocus, false);
|
expect(textField1.canRequestFocus, false);
|
||||||
// Open the dropdown menu.
|
// Open the dropdown menu.
|
||||||
await tester.tap(textFieldFinder1);
|
await tester.tap(textFieldFinder1);
|
||||||
await tester.pump();
|
await tester.pump();
|
||||||
@ -1329,7 +1329,7 @@ void main() {
|
|||||||
|
|
||||||
final Finder textFieldFinder = find.byType(TextField);
|
final Finder textFieldFinder = find.byType(TextField);
|
||||||
final TextField textField = tester.widget<TextField>(textFieldFinder);
|
final TextField textField = tester.widget<TextField>(textFieldFinder);
|
||||||
expect(textField.focusNode!.canRequestFocus, false);
|
expect(textField.canRequestFocus, false);
|
||||||
|
|
||||||
final TestGesture gesture = await tester.createGesture(kind: PointerDeviceKind.mouse, pointer: 1);
|
final TestGesture gesture = await tester.createGesture(kind: PointerDeviceKind.mouse, pointer: 1);
|
||||||
await gesture.moveTo(tester.getCenter(textFieldFinder));
|
await gesture.moveTo(tester.getCenter(textFieldFinder));
|
||||||
@ -1526,6 +1526,7 @@ void main() {
|
|||||||
// Item 5 should show up.
|
// Item 5 should show up.
|
||||||
expect(find.text('Item 5').hitTestable(), findsOneWidget);
|
expect(find.text('Item 5').hitTestable(), findsOneWidget);
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
enum TestMenu {
|
enum TestMenu {
|
||||||
|
@ -15568,7 +15568,6 @@ void main() {
|
|||||||
expect(focusNode.hasFocus, isTrue);
|
expect(focusNode.hasFocus, isTrue);
|
||||||
|
|
||||||
// Set canRequestFocus to false: the text field cannot be focused when it is tapped/long pressed.
|
// Set canRequestFocus to false: the text field cannot be focused when it is tapped/long pressed.
|
||||||
focusNode.canRequestFocus = false;
|
|
||||||
await tester.pumpWidget(
|
await tester.pumpWidget(
|
||||||
boilerplate(
|
boilerplate(
|
||||||
child: TextField(
|
child: TextField(
|
||||||
@ -15750,9 +15749,7 @@ void main() {
|
|||||||
}, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.iOS, TargetPlatform.macOS }));
|
}, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.iOS, TargetPlatform.macOS }));
|
||||||
|
|
||||||
testWidgets('Right clicking cannot request focus if canRequestFocus is false', (WidgetTester tester) async {
|
testWidgets('Right clicking cannot request focus if canRequestFocus is false', (WidgetTester tester) async {
|
||||||
final FocusNode focusNode = FocusNode(
|
final FocusNode focusNode = FocusNode();
|
||||||
canRequestFocus: false,
|
|
||||||
);
|
|
||||||
final UniqueKey key = UniqueKey();
|
final UniqueKey key = UniqueKey();
|
||||||
await tester.pumpWidget(
|
await tester.pumpWidget(
|
||||||
MaterialApp(
|
MaterialApp(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user