@@ -17,6 +17,7 @@ library;
1717import 'dart:async' ;
1818import 'dart:math' as math;
1919import 'dart:ui' as ui hide TextStyle;
20+ import 'dart:ui' ;
2021
2122import 'package:characters/characters.dart' show CharacterRange, StringCharacters;
2223import '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