Use the shortcuts temporary solution only on web (#74768)
This commit is contained in:
@@ -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<CupertinoTextField> 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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1290,35 +1290,40 @@ class _TextFieldState extends State<TextField> 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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<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.
|
||||
///
|
||||
|
||||
Reference in New Issue
Block a user