Skip to content

Commit 7fd1f42

Browse files
author
Renzo Olivares
committed
update defaults for selectionHeightStyle and selectionWidthStyle
1 parent a296fb9 commit 7fd1f42

6 files changed

Lines changed: 79 additions & 22 deletions

File tree

‎packages/flutter/lib/src/cupertino/text_field.dart‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ class CupertinoTextField extends StatefulWidget {
207207
///
208208
/// The [selectionHeightStyle] and [selectionWidthStyle] properties allow
209209
/// changing the shape of the selection highlighting. These properties default
210-
/// to [ui.BoxHeightStyle.tight] and [ui.BoxWidthStyle.tight], respectively.
210+
/// to [EditableText.defaultSelectionHeightStyle] and [EditableText.defaultSelectionWidthStyle], respectively.
211211
///
212212
/// The [autocorrect], [autofocus], [clearButtonMode], [dragStartBehavior],
213213
/// [expands], [obscureText], [prefixMode], [readOnly], [scrollPadding],
@@ -283,8 +283,8 @@ class CupertinoTextField extends StatefulWidget {
283283
this.cursorRadius = const Radius.circular(2.0),
284284
this.cursorOpacityAnimates = true,
285285
this.cursorColor,
286-
this.selectionHeightStyle = ui.BoxHeightStyle.max,
287-
this.selectionWidthStyle = ui.BoxWidthStyle.max,
286+
this.selectionHeightStyle,
287+
this.selectionWidthStyle,
288288
this.keyboardAppearance,
289289
this.scrollPadding = const EdgeInsets.all(20.0),
290290
this.dragStartBehavior = DragStartBehavior.start,
@@ -729,12 +729,12 @@ class CupertinoTextField extends StatefulWidget {
729729
/// Controls how tall the selection highlight boxes are computed to be.
730730
///
731731
/// See [ui.BoxHeightStyle] for details on available styles.
732-
final ui.BoxHeightStyle selectionHeightStyle;
732+
final ui.BoxHeightStyle? selectionHeightStyle;
733733

734734
/// Controls how wide the selection highlight boxes are computed to be.
735735
///
736736
/// See [ui.BoxWidthStyle] for details on available styles.
737-
final ui.BoxWidthStyle selectionWidthStyle;
737+
final ui.BoxWidthStyle? selectionWidthStyle;
738738

739739
/// The appearance of the keyboard.
740740
///

‎packages/flutter/lib/src/cupertino/text_form_field_row.dart‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5+
import 'dart:ui' as ui show BoxHeightStyle, BoxWidthStyle;
6+
57
import 'package:flutter/foundation.dart';
68
import 'package:flutter/services.dart';
79
import 'package:flutter/widgets.dart';
@@ -159,6 +161,8 @@ class CupertinoTextFormFieldRow extends FormField<String> {
159161
),
160162
EditableTextContextMenuBuilder? contextMenuBuilder = _defaultContextMenuBuilder,
161163
SpellCheckConfiguration? spellCheckConfiguration,
164+
ui.BoxHeightStyle? selectionHeightStyle,
165+
ui.BoxWidthStyle? selectionWidthStyle,
162166
super.restorationId,
163167
}) : assert(initialValue == null || controller == null),
164168
assert(obscuringCharacter.length == 1),
@@ -236,6 +240,8 @@ class CupertinoTextFormFieldRow extends FormField<String> {
236240
placeholderStyle: placeholderStyle,
237241
contextMenuBuilder: contextMenuBuilder,
238242
spellCheckConfiguration: spellCheckConfiguration,
243+
selectionHeightStyle: selectionHeightStyle,
244+
selectionWidthStyle: selectionWidthStyle,
239245
),
240246
),
241247
);

‎packages/flutter/lib/src/material/selectable_text.dart‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,8 @@ class SelectableText extends StatefulWidget {
184184
this.cursorRadius,
185185
this.cursorColor,
186186
this.selectionColor,
187-
this.selectionHeightStyle = ui.BoxHeightStyle.max,
188-
this.selectionWidthStyle = ui.BoxWidthStyle.max,
187+
this.selectionHeightStyle,
188+
this.selectionWidthStyle,
189189
this.dragStartBehavior = DragStartBehavior.start,
190190
this.enableInteractiveSelection = true,
191191
this.selectionControls,
@@ -375,12 +375,12 @@ class SelectableText extends StatefulWidget {
375375
/// Controls how tall the selection highlight boxes are computed to be.
376376
///
377377
/// See [ui.BoxHeightStyle] for details on available styles.
378-
final ui.BoxHeightStyle selectionHeightStyle;
378+
final ui.BoxHeightStyle? selectionHeightStyle;
379379

380380
/// Controls how wide the selection highlight boxes are computed to be.
381381
///
382382
/// See [ui.BoxWidthStyle] for details on available styles.
383-
final ui.BoxWidthStyle selectionWidthStyle;
383+
final ui.BoxWidthStyle? selectionWidthStyle;
384384

385385
/// {@macro flutter.widgets.editableText.enableInteractiveSelection}
386386
final bool enableInteractiveSelection;

‎packages/flutter/lib/src/material/text_field.dart‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ class TextField extends StatefulWidget {
232232
///
233233
/// The [selectionHeightStyle] and [selectionWidthStyle] properties allow
234234
/// changing the shape of the selection highlighting. These properties default
235-
/// to [ui.BoxHeightStyle.tight] and [ui.BoxWidthStyle.tight], respectively.
235+
/// to [EditableText.defaultSelectionHeightStyle] and [EditableText.defaultSelectionHeightStyle], respectively.
236236
///
237237
/// See also:
238238
///
@@ -286,8 +286,8 @@ class TextField extends StatefulWidget {
286286
this.cursorOpacityAnimates,
287287
this.cursorColor,
288288
this.cursorErrorColor,
289-
this.selectionHeightStyle = ui.BoxHeightStyle.max,
290-
this.selectionWidthStyle = ui.BoxWidthStyle.max,
289+
this.selectionHeightStyle,
290+
this.selectionWidthStyle,
291291
this.keyboardAppearance,
292292
this.scrollPadding = const EdgeInsets.all(20.0),
293293
this.dragStartBehavior = DragStartBehavior.start,
@@ -643,12 +643,12 @@ class TextField extends StatefulWidget {
643643
/// Controls how tall the selection highlight boxes are computed to be.
644644
///
645645
/// See [ui.BoxHeightStyle] for details on available styles.
646-
final ui.BoxHeightStyle selectionHeightStyle;
646+
final ui.BoxHeightStyle? selectionHeightStyle;
647647

648648
/// Controls how wide the selection highlight boxes are computed to be.
649649
///
650650
/// See [ui.BoxWidthStyle] for details on available styles.
651-
final ui.BoxWidthStyle selectionWidthStyle;
651+
final ui.BoxWidthStyle? selectionWidthStyle;
652652

653653
/// The appearance of the keyboard.
654654
///

‎packages/flutter/lib/src/material/text_form_field.dart‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,8 @@ class TextFormField extends FormField<String> {
178178
UndoHistoryController? undoController,
179179
AppPrivateCommandCallback? onAppPrivateCommand,
180180
bool? cursorOpacityAnimates,
181-
ui.BoxHeightStyle selectionHeightStyle = ui.BoxHeightStyle.tight,
182-
ui.BoxWidthStyle selectionWidthStyle = ui.BoxWidthStyle.tight,
181+
ui.BoxHeightStyle? selectionHeightStyle,
182+
ui.BoxWidthStyle? selectionWidthStyle,
183183
DragStartBehavior dragStartBehavior = DragStartBehavior.start,
184184
ContentInsertionConfiguration? contentInsertionConfiguration,
185185
MaterialStatesController? statesController,

‎packages/flutter/lib/src/widgets/editable_text.dart‎

Lines changed: 57 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ library;
1717
import 'dart:async';
1818
import 'dart:math' as math;
1919
import 'dart:ui' as ui hide TextStyle;
20+
import 'dart:ui';
2021

2122
import 'package:characters/characters.dart' show CharacterRange, StringCharacters;
2223
import 'package:flutter/foundation.dart';
@@ -876,8 +877,8 @@ class EditableText extends StatefulWidget {
876877
this.cursorOpacityAnimates = false,
877878
this.cursorOffset,
878879
this.paintCursorAboveText = false,
879-
this.selectionHeightStyle = ui.BoxHeightStyle.max,
880-
this.selectionWidthStyle = ui.BoxWidthStyle.max,
880+
ui.BoxHeightStyle? selectionHeightStyle,
881+
ui.BoxWidthStyle? selectionWidthStyle,
881882
this.scrollPadding = const EdgeInsets.all(20.0),
882883
this.keyboardAppearance = Brightness.light,
883884
this.dragStartBehavior = DragStartBehavior.start,
@@ -962,7 +963,9 @@ class EditableText extends StatefulWidget {
962963
...inputFormatters ?? const Iterable<TextInputFormatter>.empty(),
963964
]
964965
: inputFormatters,
965-
showCursor = showCursor ?? !readOnly;
966+
showCursor = showCursor ?? !readOnly,
967+
selectionHeightStyle = selectionHeightStyle ?? defaultSelectionHeightStyle,
968+
selectionWidthStyle = selectionWidthStyle ?? defaultSelectionWidthStyle;
966969

967970
/// Controls the text being edited.
968971
final TextEditingController controller;
@@ -2037,6 +2040,52 @@ class EditableText extends StatefulWidget {
20372040
/// {@macro flutter.services.TextInputConfiguration.hintLocales}
20382041
final List<Locale>? hintLocales;
20392042

2043+
/// The default value for [selectionHeightStyle].
2044+
///
2045+
/// On web platforms, this defaults to [ui.BoxHeightStyle.max].
2046+
///
2047+
/// On native platforms, this defaults to [ui.BoxHeightStyle.includeLineSpacingMiddle] for all
2048+
/// platforms.
2049+
static ui.BoxHeightStyle get defaultSelectionHeightStyle {
2050+
if (kIsWeb) {
2051+
return ui.BoxHeightStyle.max;
2052+
}
2053+
switch (defaultTargetPlatform) {
2054+
case TargetPlatform.android:
2055+
case TargetPlatform.fuchsia:
2056+
case TargetPlatform.iOS:
2057+
case TargetPlatform.linux:
2058+
case TargetPlatform.macOS:
2059+
case TargetPlatform.windows:
2060+
return ui.BoxHeightStyle.includeLineSpacingMiddle;
2061+
}
2062+
}
2063+
2064+
/// The default value for [selectionWidthStyle].
2065+
///
2066+
/// On web platforms, this defaults to [ui.BoxWidthStyle.max] for iOS and
2067+
/// [ui.BoxWidthStyle.tight] for all others.
2068+
///
2069+
/// On non-web platforms, this defaults to [ui.BoxWidthStyle.max] for all
2070+
/// platforms.
2071+
static ui.BoxWidthStyle get defaultSelectionWidthStyle {
2072+
if (kIsWeb) {
2073+
if (defaultTargetPlatform == TargetPlatform.iOS) {
2074+
return ui.BoxWidthStyle.max;
2075+
}
2076+
return ui.BoxWidthStyle.tight;
2077+
}
2078+
switch (defaultTargetPlatform) {
2079+
case TargetPlatform.android:
2080+
case TargetPlatform.fuchsia:
2081+
case TargetPlatform.iOS:
2082+
case TargetPlatform.linux:
2083+
case TargetPlatform.macOS:
2084+
case TargetPlatform.windows:
2085+
return ui.BoxWidthStyle.max;
2086+
}
2087+
}
2088+
20402089
/// The default value for [stylusHandwritingEnabled].
20412090
static const bool defaultStylusHandwritingEnabled = true;
20422091

@@ -5899,15 +5948,17 @@ class _Editable extends MultiChildRenderObjectWidget {
58995948
this.cursorRadius,
59005949
required this.cursorOffset,
59015950
required this.paintCursorAboveText,
5902-
this.selectionHeightStyle = ui.BoxHeightStyle.tight,
5903-
this.selectionWidthStyle = ui.BoxWidthStyle.tight,
5951+
ui.BoxHeightStyle? selectionHeightStyle,
5952+
ui.BoxWidthStyle? selectionWidthStyle,
59045953
this.enableInteractiveSelection = true,
59055954
required this.textSelectionDelegate,
59065955
required this.devicePixelRatio,
59075956
this.promptRectRange,
59085957
this.promptRectColor,
59095958
required this.clipBehavior,
5910-
}) : super(children: WidgetSpan.extractFromInlineSpan(inlineSpan, textScaler));
5959+
}) : selectionHeightStyle = selectionHeightStyle ?? EditableText.defaultSelectionHeightStyle,
5960+
selectionWidthStyle = selectionWidthStyle ?? EditableText.defaultSelectionWidthStyle,
5961+
super(children: WidgetSpan.extractFromInlineSpan(inlineSpan, textScaler));
59115962

59125963
final InlineSpan inlineSpan;
59135964
final TextEditingValue value;

0 commit comments

Comments
 (0)