Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
7a739151
Unverified
Commit
7a739151
authored
Jul 01, 2021
by
Renzo Olivares
Committed by
GitHub
Jul 01, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Expose selectionHeightStyle and SelectionWidthStyle on SelectableText (#85640)
parent
077457af
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
129 additions
and
3 deletions
+129
-3
selectable_text.dart
packages/flutter/lib/src/material/selectable_text.dart
+23
-3
selectable_text_test.dart
packages/flutter/test/widgets/selectable_text_test.dart
+106
-0
No files found.
packages/flutter/lib/src/material/selectable_text.dart
View file @
7a739151
...
...
@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import
'dart:ui'
as
ui
show
BoxHeightStyle
,
BoxWidthStyle
;
import
'package:flutter/cupertino.dart'
;
import
'package:flutter/foundation.dart'
;
import
'package:flutter/gestures.dart'
;
...
...
@@ -168,9 +170,9 @@ class SelectableText extends StatefulWidget {
/// closest enclosing [DefaultTextStyle].
///
/// The [showCursor], [autofocus], [dragStartBehavior],
and [data] parameters
///
must not be null. If specified, the [maxLines] argument must be greater
/// than zero.
/// The [showCursor], [autofocus], [dragStartBehavior],
[selectionHeightStyle],
///
[selectionWidthStyle] and [data] parameters must not be null. If specified,
/// th
e [maxLines] argument must be greater th
an zero.
const
SelectableText
(
String
this
.
data
,
{
Key
?
key
,
...
...
@@ -189,6 +191,8 @@ class SelectableText extends StatefulWidget {
this
.
cursorHeight
,
this
.
cursorRadius
,
this
.
cursorColor
,
this
.
selectionHeightStyle
=
ui
.
BoxHeightStyle
.
tight
,
this
.
selectionWidthStyle
=
ui
.
BoxWidthStyle
.
tight
,
this
.
dragStartBehavior
=
DragStartBehavior
.
start
,
this
.
enableInteractiveSelection
=
true
,
this
.
selectionControls
,
...
...
@@ -200,6 +204,8 @@ class SelectableText extends StatefulWidget {
})
:
assert
(
showCursor
!=
null
),
assert
(
autofocus
!=
null
),
assert
(
dragStartBehavior
!=
null
),
assert
(
selectionHeightStyle
!=
null
),
assert
(
selectionWidthStyle
!=
null
),
assert
(
maxLines
==
null
||
maxLines
>
0
),
assert
(
minLines
==
null
||
minLines
>
0
),
assert
(
...
...
@@ -242,6 +248,8 @@ class SelectableText extends StatefulWidget {
this
.
cursorHeight
,
this
.
cursorRadius
,
this
.
cursorColor
,
this
.
selectionHeightStyle
=
ui
.
BoxHeightStyle
.
tight
,
this
.
selectionWidthStyle
=
ui
.
BoxWidthStyle
.
tight
,
this
.
dragStartBehavior
=
DragStartBehavior
.
start
,
this
.
enableInteractiveSelection
=
true
,
this
.
selectionControls
,
...
...
@@ -352,6 +360,16 @@ class SelectableText extends StatefulWidget {
/// Defaults to the theme's `cursorColor` when null.
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}
final
bool
enableInteractiveSelection
;
...
...
@@ -665,6 +683,8 @@ class _SelectableTextState extends State<SelectableText> with AutomaticKeepAlive
cursorHeight:
widget
.
cursorHeight
,
cursorRadius:
cursorRadius
,
cursorColor:
cursorColor
,
selectionHeightStyle:
widget
.
selectionHeightStyle
,
selectionWidthStyle:
widget
.
selectionWidthStyle
,
cursorOpacityAnimates:
cursorOpacityAnimates
,
cursorOffset:
cursorOffset
,
paintCursorAboveText:
paintCursorAboveText
,
...
...
packages/flutter/test/widgets/selectable_text_test.dart
View file @
7a739151
...
...
@@ -3,6 +3,8 @@
// found in the LICENSE file.
@TestOn
(
'!chrome'
)
import
'dart:ui'
as
ui
show
BoxHeightStyle
,
BoxWidthStyle
;
import
'package:flutter/cupertino.dart'
;
import
'package:flutter/foundation.dart'
;
import
'package:flutter/gestures.dart'
;
...
...
@@ -4799,4 +4801,108 @@ void main() {
expect
(
selection
!.
baseOffset
,
6
);
expect
(
selection
!.
extentOffset
,
14
);
},
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'
),
);
});
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment