diff --git a/packages/flutter/lib/src/cupertino/text_field.dart b/packages/flutter/lib/src/cupertino/text_field.dart index a3adfbc0f0..d4c76133a1 100644 --- a/packages/flutter/lib/src/cupertino/text_field.dart +++ b/packages/flutter/lib/src/cupertino/text_field.dart @@ -4,7 +4,7 @@ import 'dart:ui' as ui show BoxHeightStyle, BoxWidthStyle; -import 'package:flutter/foundation.dart' show defaultTargetPlatform; +import 'package:flutter/foundation.dart' show defaultTargetPlatform, kIsWeb; import 'package:flutter/gestures.dart'; import 'package:flutter/rendering.dart'; import 'package:flutter/services.dart'; @@ -1201,32 +1201,37 @@ class _CupertinoTextFieldState extends State with Restoratio ), ); - return Shortcuts( - shortcuts: scrollShortcutOverrides, - child: Semantics( - enabled: enabled, - onTap: !enabled || widget.readOnly ? null : () { - if (!controller.selection.isValid) { - controller.selection = TextSelection.collapsed(offset: controller.text.length); - } - _requestKeyboard(); - }, - child: IgnorePointer( - ignoring: !enabled, - child: Container( - decoration: effectiveDecoration, - child: _selectionGestureDetectorBuilder.buildGestureDetector( - behavior: HitTestBehavior.translucent, - child: Align( - alignment: Alignment(-1.0, _textAlignVertical.y), - widthFactor: 1.0, - heightFactor: 1.0, - child: _addTextDependentAttachments(paddedEditable, textStyle, placeholderStyle), - ), + final Widget child = Semantics( + enabled: enabled, + onTap: !enabled || widget.readOnly ? null : () { + if (!controller.selection.isValid) { + controller.selection = TextSelection.collapsed(offset: controller.text.length); + } + _requestKeyboard(); + }, + child: IgnorePointer( + ignoring: !enabled, + child: Container( + decoration: effectiveDecoration, + child: _selectionGestureDetectorBuilder.buildGestureDetector( + behavior: HitTestBehavior.translucent, + child: Align( + alignment: Alignment(-1.0, _textAlignVertical.y), + widthFactor: 1.0, + heightFactor: 1.0, + child: _addTextDependentAttachments(paddedEditable, textStyle, placeholderStyle), ), ), ), ), ); + + if (kIsWeb) { + return Shortcuts( + shortcuts: scrollShortcutOverrides, + child: child, + ); + } + return child; } } diff --git a/packages/flutter/lib/src/material/text_field.dart b/packages/flutter/lib/src/material/text_field.dart index d524ab3b29..9ba8f46734 100644 --- a/packages/flutter/lib/src/material/text_field.dart +++ b/packages/flutter/lib/src/material/text_field.dart @@ -1290,35 +1290,40 @@ class _TextFieldState extends State with RestorationMixin implements semanticsMaxValueLength = null; } - return MouseRegion( + child = MouseRegion( cursor: effectiveMouseCursor, onEnter: (PointerEnterEvent event) => _handleHover(true), onExit: (PointerExitEvent event) => _handleHover(false), - child: Shortcuts( - shortcuts: scrollShortcutOverrides, - child: IgnorePointer( - ignoring: !_isEnabled, - child: AnimatedBuilder( - animation: controller, // changes the _currentLength - builder: (BuildContext context, Widget? child) { - return Semantics( - maxValueLength: semanticsMaxValueLength, - currentValueLength: _currentLength, - onTap: widget.readOnly ? null : () { - if (!_effectiveController.selection.isValid) - _effectiveController.selection = TextSelection.collapsed(offset: _effectiveController.text.length); - _requestKeyboard(); - }, - child: child, - ); - }, - child: _selectionGestureDetectorBuilder.buildGestureDetector( - behavior: HitTestBehavior.translucent, + child: IgnorePointer( + ignoring: !_isEnabled, + child: AnimatedBuilder( + animation: controller, // changes the _currentLength + builder: (BuildContext context, Widget? child) { + return Semantics( + maxValueLength: semanticsMaxValueLength, + currentValueLength: _currentLength, + onTap: widget.readOnly ? null : () { + if (!_effectiveController.selection.isValid) + _effectiveController.selection = TextSelection.collapsed(offset: _effectiveController.text.length); + _requestKeyboard(); + }, child: child, - ), + ); + }, + child: _selectionGestureDetectorBuilder.buildGestureDetector( + behavior: HitTestBehavior.translucent, + child: child, ), ), ), ); + + if (kIsWeb) { + return Shortcuts( + shortcuts: scrollShortcutOverrides, + child: child, + ); + } + return child; } } diff --git a/packages/flutter/lib/src/widgets/editable_text.dart b/packages/flutter/lib/src/widgets/editable_text.dart index 377d072795..c58d7552af 100644 --- a/packages/flutter/lib/src/widgets/editable_text.dart +++ b/packages/flutter/lib/src/widgets/editable_text.dart @@ -58,15 +58,13 @@ const int _kObscureShowLatestCharCursorTicks = 3; /// A map used to disable scrolling shortcuts in text fields. /// /// This is a temporary fix for: https://github.com/flutter/flutter/issues/74191 -final Map scrollShortcutOverrides = kIsWeb - ? { - LogicalKeySet(LogicalKeyboardKey.space): DoNothingAndStopPropagationIntent(), - LogicalKeySet(LogicalKeyboardKey.arrowUp): DoNothingAndStopPropagationIntent(), - LogicalKeySet(LogicalKeyboardKey.arrowDown): DoNothingAndStopPropagationIntent(), - LogicalKeySet(LogicalKeyboardKey.arrowLeft): DoNothingAndStopPropagationIntent(), - LogicalKeySet(LogicalKeyboardKey.arrowRight): DoNothingAndStopPropagationIntent(), - } - : {}; +final Map scrollShortcutOverrides = { + LogicalKeySet(LogicalKeyboardKey.space): DoNothingAndStopPropagationIntent(), + LogicalKeySet(LogicalKeyboardKey.arrowUp): DoNothingAndStopPropagationIntent(), + LogicalKeySet(LogicalKeyboardKey.arrowDown): DoNothingAndStopPropagationIntent(), + LogicalKeySet(LogicalKeyboardKey.arrowLeft): DoNothingAndStopPropagationIntent(), + LogicalKeySet(LogicalKeyboardKey.arrowRight): DoNothingAndStopPropagationIntent(), +}; /// A controller for an editable text field. ///