Use the shortcuts temporary solution only on web (#74768) (#74826)
Co-authored-by: Mouad Debbar <mouad.debbar@gmail.com>
diff --git a/packages/flutter/lib/src/cupertino/text_field.dart b/packages/flutter/lib/src/cupertino/text_field.dart
index a3adfbc..d4c7613 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 @@
),
);
- 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 d524ab3..9ba8f46 100644
--- a/packages/flutter/lib/src/material/text_field.dart
+++ b/packages/flutter/lib/src/material/text_field.dart
@@ -1290,35 +1290,40 @@
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 377d072..c58d755 100644
--- a/packages/flutter/lib/src/widgets/editable_text.dart
+++ b/packages/flutter/lib/src/widgets/editable_text.dart
@@ -58,15 +58,13 @@
/// 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<LogicalKeySet, Intent> scrollShortcutOverrides = kIsWeb
- ? <LogicalKeySet, Intent>{
- LogicalKeySet(LogicalKeyboardKey.space): DoNothingAndStopPropagationIntent(),
- LogicalKeySet(LogicalKeyboardKey.arrowUp): DoNothingAndStopPropagationIntent(),
- LogicalKeySet(LogicalKeyboardKey.arrowDown): DoNothingAndStopPropagationIntent(),
- LogicalKeySet(LogicalKeyboardKey.arrowLeft): DoNothingAndStopPropagationIntent(),
- LogicalKeySet(LogicalKeyboardKey.arrowRight): DoNothingAndStopPropagationIntent(),
- }
- : <LogicalKeySet, Intent>{};
+final Map<LogicalKeySet, Intent> scrollShortcutOverrides = <LogicalKeySet, Intent>{
+ 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.
///