Unverified Commit 7a739151 authored by Renzo Olivares's avatar Renzo Olivares Committed by GitHub

Expose selectionHeightStyle and SelectionWidthStyle on SelectableText (#85640)

parent 077457af
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
import 'dart:ui' as ui show BoxHeightStyle, BoxWidthStyle;
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart'; import 'package:flutter/gestures.dart';
...@@ -168,9 +170,9 @@ class SelectableText extends StatefulWidget { ...@@ -168,9 +170,9 @@ class SelectableText extends StatefulWidget {
/// closest enclosing [DefaultTextStyle]. /// closest enclosing [DefaultTextStyle].
/// ///
/// The [showCursor], [autofocus], [dragStartBehavior], and [data] parameters /// The [showCursor], [autofocus], [dragStartBehavior], [selectionHeightStyle],
/// must not be null. If specified, the [maxLines] argument must be greater /// [selectionWidthStyle] and [data] parameters must not be null. If specified,
/// than zero. /// the [maxLines] argument must be greater than zero.
const SelectableText( const SelectableText(
String this.data, { String this.data, {
Key? key, Key? key,
...@@ -189,6 +191,8 @@ class SelectableText extends StatefulWidget { ...@@ -189,6 +191,8 @@ class SelectableText extends StatefulWidget {
this.cursorHeight, this.cursorHeight,
this.cursorRadius, this.cursorRadius,
this.cursorColor, this.cursorColor,
this.selectionHeightStyle = ui.BoxHeightStyle.tight,
this.selectionWidthStyle = ui.BoxWidthStyle.tight,
this.dragStartBehavior = DragStartBehavior.start, this.dragStartBehavior = DragStartBehavior.start,
this.enableInteractiveSelection = true, this.enableInteractiveSelection = true,
this.selectionControls, this.selectionControls,
...@@ -200,6 +204,8 @@ class SelectableText extends StatefulWidget { ...@@ -200,6 +204,8 @@ class SelectableText extends StatefulWidget {
}) : assert(showCursor != null), }) : assert(showCursor != null),
assert(autofocus != null), assert(autofocus != null),
assert(dragStartBehavior != null), assert(dragStartBehavior != null),
assert(selectionHeightStyle != null),
assert(selectionWidthStyle != null),
assert(maxLines == null || maxLines > 0), assert(maxLines == null || maxLines > 0),
assert(minLines == null || minLines > 0), assert(minLines == null || minLines > 0),
assert( assert(
...@@ -242,6 +248,8 @@ class SelectableText extends StatefulWidget { ...@@ -242,6 +248,8 @@ class SelectableText extends StatefulWidget {
this.cursorHeight, this.cursorHeight,
this.cursorRadius, this.cursorRadius,
this.cursorColor, this.cursorColor,
this.selectionHeightStyle = ui.BoxHeightStyle.tight,
this.selectionWidthStyle = ui.BoxWidthStyle.tight,
this.dragStartBehavior = DragStartBehavior.start, this.dragStartBehavior = DragStartBehavior.start,
this.enableInteractiveSelection = true, this.enableInteractiveSelection = true,
this.selectionControls, this.selectionControls,
...@@ -352,6 +360,16 @@ class SelectableText extends StatefulWidget { ...@@ -352,6 +360,16 @@ class SelectableText extends StatefulWidget {
/// Defaults to the theme's `cursorColor` when null. /// Defaults to the theme's `cursorColor` when null.
final Color? cursorColor; final Color? cursorColor;
/// Controls how tall the selection highlight boxes are computed to be.
///
/// See [ui.BoxHeightStyle] for details on available styles.
final ui.BoxHeightStyle selectionHeightStyle;
/// Controls how wide the selection highlight boxes are computed to be.
///
/// See [ui.BoxWidthStyle] for details on available styles.
final ui.BoxWidthStyle selectionWidthStyle;
/// {@macro flutter.widgets.editableText.enableInteractiveSelection} /// {@macro flutter.widgets.editableText.enableInteractiveSelection}
final bool enableInteractiveSelection; final bool enableInteractiveSelection;
...@@ -665,6 +683,8 @@ class _SelectableTextState extends State<SelectableText> with AutomaticKeepAlive ...@@ -665,6 +683,8 @@ class _SelectableTextState extends State<SelectableText> with AutomaticKeepAlive
cursorHeight: widget.cursorHeight, cursorHeight: widget.cursorHeight,
cursorRadius: cursorRadius, cursorRadius: cursorRadius,
cursorColor: cursorColor, cursorColor: cursorColor,
selectionHeightStyle: widget.selectionHeightStyle,
selectionWidthStyle: widget.selectionWidthStyle,
cursorOpacityAnimates: cursorOpacityAnimates, cursorOpacityAnimates: cursorOpacityAnimates,
cursorOffset: cursorOffset, cursorOffset: cursorOffset,
paintCursorAboveText: paintCursorAboveText, paintCursorAboveText: paintCursorAboveText,
......
...@@ -3,6 +3,8 @@ ...@@ -3,6 +3,8 @@
// found in the LICENSE file. // found in the LICENSE file.
@TestOn('!chrome') @TestOn('!chrome')
import 'dart:ui' as ui show BoxHeightStyle, BoxWidthStyle;
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart'; import 'package:flutter/gestures.dart';
...@@ -4799,4 +4801,108 @@ void main() { ...@@ -4799,4 +4801,108 @@ void main() {
expect(selection!.baseOffset, 6); expect(selection!.baseOffset, 6);
expect(selection!.extentOffset, 14); expect(selection!.extentOffset, 14);
}, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.iOS, TargetPlatform.android })); }, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.iOS, TargetPlatform.android }));
testWidgets('text selection style 1', (WidgetTester tester) async {
await tester.pumpWidget(
MaterialApp(
home: Material(
child: Center(
child: Column(
children: const <Widget>[
SelectableText.rich(
TextSpan(
children: <TextSpan>[
TextSpan(
text: 'Atwater Peel ',
style: TextStyle(
fontSize: 30.0,
),
),
TextSpan(
text: 'Sherbrooke Bonaventure ',
style: TextStyle(
fontSize: 15.0,
),
),
TextSpan(
text: 'hi wassup!',
style: TextStyle(
fontSize: 10.0,
),
),
],
),
key: Key('field0'),
selectionHeightStyle: ui.BoxHeightStyle.includeLineSpacingTop,
selectionWidthStyle: ui.BoxWidthStyle.max,
),
],
),
),
),
),
);
final EditableText editableTextWidget = tester.widget(find.byType(EditableText).first);
final TextEditingController controller = editableTextWidget.controller;
controller.selection = const TextSelection(baseOffset: 0, extentOffset: 46);
await tester.pump();
await expectLater(
find.byType(MaterialApp),
matchesGoldenFile('selectable_text_golden.TextSelectionStyle.1.png'),
);
});
testWidgets('text selection style 2', (WidgetTester tester) async {
await tester.pumpWidget(
MaterialApp(
home: Material(
child: Center(
child: Column(
children: const <Widget>[
SelectableText.rich(
TextSpan(
children: <TextSpan>[
TextSpan(
text: 'Atwater Peel ',
style: TextStyle(
fontSize: 30.0,
),
),
TextSpan(
text: 'Sherbrooke Bonaventure ',
style: TextStyle(
fontSize: 15.0,
),
),
TextSpan(
text: 'hi wassup!',
style: TextStyle(
fontSize: 10.0,
),
),
],
),
key: Key('field0'),
selectionHeightStyle: ui.BoxHeightStyle.includeLineSpacingBottom,
selectionWidthStyle: ui.BoxWidthStyle.tight,
),
],
),
),
),
),
);
final EditableText editableTextWidget = tester.widget(find.byType(EditableText).first);
final TextEditingController controller = editableTextWidget.controller;
controller.selection = const TextSelection(baseOffset: 0, extentOffset: 46);
await tester.pump();
await expectLater(
find.byType(MaterialApp),
matchesGoldenFile('selectable_text_golden.TextSelectionStyle.2.png'),
);
});
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment