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
4bae7715
Unverified
Commit
4bae7715
authored
Jun 03, 2020
by
MH Johnson
Committed by
GitHub
Jun 03, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Line Heights] Add textHeightBehavior to SelectableText. (#58530)
parent
79e24094
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
52 additions
and
0 deletions
+52
-0
selectable_text.dart
packages/flutter/lib/src/material/selectable_text.dart
+7
-0
editable.dart
packages/flutter/lib/src/rendering/editable.dart
+11
-0
editable_text.dart
packages/flutter/lib/src/widgets/editable_text.dart
+10
-0
selectable_text_test.dart
packages/flutter/test/widgets/selectable_text_test.dart
+24
-0
No files found.
packages/flutter/lib/src/material/selectable_text.dart
View file @
4bae7715
...
@@ -221,6 +221,7 @@ class SelectableText extends StatefulWidget {
...
@@ -221,6 +221,7 @@ class SelectableText extends StatefulWidget {
this
.
enableInteractiveSelection
=
true
,
this
.
enableInteractiveSelection
=
true
,
this
.
onTap
,
this
.
onTap
,
this
.
scrollPhysics
,
this
.
scrollPhysics
,
this
.
textHeightBehavior
,
this
.
textWidthBasis
,
this
.
textWidthBasis
,
})
:
assert
(
showCursor
!=
null
),
})
:
assert
(
showCursor
!=
null
),
assert
(
autofocus
!=
null
),
assert
(
autofocus
!=
null
),
...
@@ -270,6 +271,7 @@ class SelectableText extends StatefulWidget {
...
@@ -270,6 +271,7 @@ class SelectableText extends StatefulWidget {
this
.
enableInteractiveSelection
=
true
,
this
.
enableInteractiveSelection
=
true
,
this
.
onTap
,
this
.
onTap
,
this
.
scrollPhysics
,
this
.
scrollPhysics
,
this
.
textHeightBehavior
,
this
.
textWidthBasis
,
this
.
textWidthBasis
,
})
:
assert
(
showCursor
!=
null
),
})
:
assert
(
showCursor
!=
null
),
assert
(
autofocus
!=
null
),
assert
(
autofocus
!=
null
),
...
@@ -406,6 +408,9 @@ class SelectableText extends StatefulWidget {
...
@@ -406,6 +408,9 @@ class SelectableText extends StatefulWidget {
/// {@macro flutter.widgets.editableText.scrollPhysics}
/// {@macro flutter.widgets.editableText.scrollPhysics}
final
ScrollPhysics
scrollPhysics
;
final
ScrollPhysics
scrollPhysics
;
/// {@macro flutter.dart:ui.textHeightBehavior}
final
TextHeightBehavior
textHeightBehavior
;
/// {@macro flutter.painting.textPainter.textWidthBasis}
/// {@macro flutter.painting.textPainter.textWidthBasis}
final
TextWidthBasis
textWidthBasis
;
final
TextWidthBasis
textWidthBasis
;
...
@@ -430,6 +435,7 @@ class SelectableText extends StatefulWidget {
...
@@ -430,6 +435,7 @@ class SelectableText extends StatefulWidget {
properties
.
add
(
DiagnosticsProperty
<
Color
>(
'cursorColor'
,
cursorColor
,
defaultValue:
null
));
properties
.
add
(
DiagnosticsProperty
<
Color
>(
'cursorColor'
,
cursorColor
,
defaultValue:
null
));
properties
.
add
(
FlagProperty
(
'selectionEnabled'
,
value:
selectionEnabled
,
defaultValue:
true
,
ifFalse:
'selection disabled'
));
properties
.
add
(
FlagProperty
(
'selectionEnabled'
,
value:
selectionEnabled
,
defaultValue:
true
,
ifFalse:
'selection disabled'
));
properties
.
add
(
DiagnosticsProperty
<
ScrollPhysics
>(
'scrollPhysics'
,
scrollPhysics
,
defaultValue:
null
));
properties
.
add
(
DiagnosticsProperty
<
ScrollPhysics
>(
'scrollPhysics'
,
scrollPhysics
,
defaultValue:
null
));
properties
.
add
(
DiagnosticsProperty
<
TextHeightBehavior
>(
'textHeightBehavior'
,
textHeightBehavior
,
defaultValue:
null
));
}
}
}
}
...
@@ -598,6 +604,7 @@ class _SelectableTextState extends State<SelectableText> with AutomaticKeepAlive
...
@@ -598,6 +604,7 @@ class _SelectableTextState extends State<SelectableText> with AutomaticKeepAlive
style:
effectiveTextStyle
,
style:
effectiveTextStyle
,
readOnly:
true
,
readOnly:
true
,
textWidthBasis:
widget
.
textWidthBasis
??
defaultTextStyle
.
textWidthBasis
,
textWidthBasis:
widget
.
textWidthBasis
??
defaultTextStyle
.
textWidthBasis
,
textHeightBehavior:
widget
.
textHeightBehavior
??
defaultTextStyle
.
textHeightBehavior
,
showSelectionHandles:
_showSelectionHandles
,
showSelectionHandles:
_showSelectionHandles
,
showCursor:
widget
.
showCursor
,
showCursor:
widget
.
showCursor
,
controller:
_controller
,
controller:
_controller
,
...
...
packages/flutter/lib/src/rendering/editable.dart
View file @
4bae7715
...
@@ -212,6 +212,7 @@ class RenderEditable extends RenderBox with RelayoutWhenSystemFontsChangeMixin {
...
@@ -212,6 +212,7 @@ class RenderEditable extends RenderBox with RelayoutWhenSystemFontsChangeMixin {
this
.
ignorePointer
=
false
,
this
.
ignorePointer
=
false
,
bool
readOnly
=
false
,
bool
readOnly
=
false
,
bool
forceLine
=
true
,
bool
forceLine
=
true
,
TextHeightBehavior
textHeightBehavior
,
TextWidthBasis
textWidthBasis
=
TextWidthBasis
.
parent
,
TextWidthBasis
textWidthBasis
=
TextWidthBasis
.
parent
,
String
obscuringCharacter
=
'•'
,
String
obscuringCharacter
=
'•'
,
bool
obscureText
=
false
,
bool
obscureText
=
false
,
...
@@ -264,6 +265,7 @@ class RenderEditable extends RenderBox with RelayoutWhenSystemFontsChangeMixin {
...
@@ -264,6 +265,7 @@ class RenderEditable extends RenderBox with RelayoutWhenSystemFontsChangeMixin {
textScaleFactor:
textScaleFactor
,
textScaleFactor:
textScaleFactor
,
locale:
locale
,
locale:
locale
,
strutStyle:
strutStyle
,
strutStyle:
strutStyle
,
textHeightBehavior:
textHeightBehavior
,
textWidthBasis:
textWidthBasis
,
textWidthBasis:
textWidthBasis
,
),
),
_cursorColor
=
cursorColor
,
_cursorColor
=
cursorColor
,
...
@@ -322,6 +324,15 @@ class RenderEditable extends RenderBox with RelayoutWhenSystemFontsChangeMixin {
...
@@ -322,6 +324,15 @@ class RenderEditable extends RenderBox with RelayoutWhenSystemFontsChangeMixin {
/// The default value of this property is false.
/// The default value of this property is false.
bool
ignorePointer
;
bool
ignorePointer
;
/// {@macro flutter.dart:ui.textHeightBehavior}
TextHeightBehavior
get
textHeightBehavior
=>
_textPainter
.
textHeightBehavior
;
set
textHeightBehavior
(
TextHeightBehavior
value
)
{
if
(
_textPainter
.
textHeightBehavior
==
value
)
return
;
_textPainter
.
textHeightBehavior
=
value
;
markNeedsTextLayout
();
}
/// {@macro flutter.widgets.text.DefaultTextStyle.textWidthBasis}
/// {@macro flutter.widgets.text.DefaultTextStyle.textWidthBasis}
TextWidthBasis
get
textWidthBasis
=>
_textPainter
.
textWidthBasis
;
TextWidthBasis
get
textWidthBasis
=>
_textPainter
.
textWidthBasis
;
set
textWidthBasis
(
TextWidthBasis
value
)
{
set
textWidthBasis
(
TextWidthBasis
value
)
{
...
...
packages/flutter/lib/src/widgets/editable_text.dart
View file @
4bae7715
...
@@ -375,6 +375,7 @@ class EditableText extends StatefulWidget {
...
@@ -375,6 +375,7 @@ class EditableText extends StatefulWidget {
this
.
minLines
,
this
.
minLines
,
this
.
expands
=
false
,
this
.
expands
=
false
,
this
.
forceLine
=
true
,
this
.
forceLine
=
true
,
this
.
textHeightBehavior
,
this
.
textWidthBasis
=
TextWidthBasis
.
parent
,
this
.
textWidthBasis
=
TextWidthBasis
.
parent
,
this
.
autofocus
=
false
,
this
.
autofocus
=
false
,
bool
showCursor
,
bool
showCursor
,
...
@@ -486,6 +487,9 @@ class EditableText extends StatefulWidget {
...
@@ -486,6 +487,9 @@ class EditableText extends StatefulWidget {
/// {@endtemplate}
/// {@endtemplate}
final
bool
obscureText
;
final
bool
obscureText
;
/// {@macro flutter.dart:ui.textHeightBehavior},
final
TextHeightBehavior
textHeightBehavior
;
/// {@macro flutter.widgets.text.DefaultTextStyle.textWidthBasis}
/// {@macro flutter.widgets.text.DefaultTextStyle.textWidthBasis}
final
TextWidthBasis
textWidthBasis
;
final
TextWidthBasis
textWidthBasis
;
...
@@ -1146,6 +1150,7 @@ class EditableText extends StatefulWidget {
...
@@ -1146,6 +1150,7 @@ class EditableText extends StatefulWidget {
properties
.
add
(
DiagnosticsProperty
<
ScrollController
>(
'scrollController'
,
scrollController
,
defaultValue:
null
));
properties
.
add
(
DiagnosticsProperty
<
ScrollController
>(
'scrollController'
,
scrollController
,
defaultValue:
null
));
properties
.
add
(
DiagnosticsProperty
<
ScrollPhysics
>(
'scrollPhysics'
,
scrollPhysics
,
defaultValue:
null
));
properties
.
add
(
DiagnosticsProperty
<
ScrollPhysics
>(
'scrollPhysics'
,
scrollPhysics
,
defaultValue:
null
));
properties
.
add
(
DiagnosticsProperty
<
Iterable
<
String
>>(
'autofillHints'
,
autofillHints
,
defaultValue:
null
));
properties
.
add
(
DiagnosticsProperty
<
Iterable
<
String
>>(
'autofillHints'
,
autofillHints
,
defaultValue:
null
));
properties
.
add
(
DiagnosticsProperty
<
TextHeightBehavior
>(
'textHeightBehavior'
,
textHeightBehavior
,
defaultValue:
null
));
}
}
}
}
...
@@ -2085,6 +2090,7 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
...
@@ -2085,6 +2090,7 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
textAlign:
widget
.
textAlign
,
textAlign:
widget
.
textAlign
,
textDirection:
_textDirection
,
textDirection:
_textDirection
,
locale:
widget
.
locale
,
locale:
widget
.
locale
,
textHeightBehavior:
widget
.
textHeightBehavior
,
textWidthBasis:
widget
.
textWidthBasis
,
textWidthBasis:
widget
.
textWidthBasis
,
obscuringCharacter:
widget
.
obscuringCharacter
,
obscuringCharacter:
widget
.
obscuringCharacter
,
obscureText:
widget
.
obscureText
,
obscureText:
widget
.
obscureText
,
...
@@ -2149,6 +2155,7 @@ class _Editable extends LeafRenderObjectWidget {
...
@@ -2149,6 +2155,7 @@ class _Editable extends LeafRenderObjectWidget {
this
.
showCursor
,
this
.
showCursor
,
this
.
forceLine
,
this
.
forceLine
,
this
.
readOnly
,
this
.
readOnly
,
this
.
textHeightBehavior
,
this
.
textWidthBasis
,
this
.
textWidthBasis
,
this
.
hasFocus
,
this
.
hasFocus
,
this
.
maxLines
,
this
.
maxLines
,
...
@@ -2206,6 +2213,7 @@ class _Editable extends LeafRenderObjectWidget {
...
@@ -2206,6 +2213,7 @@ class _Editable extends LeafRenderObjectWidget {
final
Locale
locale
;
final
Locale
locale
;
final
String
obscuringCharacter
;
final
String
obscuringCharacter
;
final
bool
obscureText
;
final
bool
obscureText
;
final
TextHeightBehavior
textHeightBehavior
;
final
TextWidthBasis
textWidthBasis
;
final
TextWidthBasis
textWidthBasis
;
final
bool
autocorrect
;
final
bool
autocorrect
;
final
SmartDashesType
smartDashesType
;
final
SmartDashesType
smartDashesType
;
...
@@ -2255,6 +2263,7 @@ class _Editable extends LeafRenderObjectWidget {
...
@@ -2255,6 +2263,7 @@ class _Editable extends LeafRenderObjectWidget {
ignorePointer:
rendererIgnoresPointer
,
ignorePointer:
rendererIgnoresPointer
,
obscuringCharacter:
obscuringCharacter
,
obscuringCharacter:
obscuringCharacter
,
obscureText:
obscureText
,
obscureText:
obscureText
,
textHeightBehavior:
textHeightBehavior
,
textWidthBasis:
textWidthBasis
,
textWidthBasis:
textWidthBasis
,
cursorWidth:
cursorWidth
,
cursorWidth:
cursorWidth
,
cursorRadius:
cursorRadius
,
cursorRadius:
cursorRadius
,
...
@@ -2295,6 +2304,7 @@ class _Editable extends LeafRenderObjectWidget {
...
@@ -2295,6 +2304,7 @@ class _Editable extends LeafRenderObjectWidget {
..
onSelectionChanged
=
onSelectionChanged
..
onSelectionChanged
=
onSelectionChanged
..
onCaretChanged
=
onCaretChanged
..
onCaretChanged
=
onCaretChanged
..
ignorePointer
=
rendererIgnoresPointer
..
ignorePointer
=
rendererIgnoresPointer
..
textHeightBehavior
=
textHeightBehavior
..
textWidthBasis
=
textWidthBasis
..
textWidthBasis
=
textWidthBasis
..
obscuringCharacter
=
obscuringCharacter
..
obscuringCharacter
=
obscuringCharacter
..
obscureText
=
obscureText
..
obscureText
=
obscureText
...
...
packages/flutter/test/widgets/selectable_text_test.dart
View file @
4bae7715
...
@@ -374,6 +374,30 @@ void main() {
...
@@ -374,6 +374,30 @@ void main() {
expect
(
textBox
.
size
,
const
Size
(
633.0
,
28.0
));
expect
(
textBox
.
size
,
const
Size
(
633.0
,
28.0
));
});
});
testWidgets
(
'can switch between textHeightBehavior'
,
(
WidgetTester
tester
)
async
{
const
String
text
=
'selectable text'
;
const
TextHeightBehavior
textHeightBehavior
=
TextHeightBehavior
(
applyHeightToFirstAscent:
false
,
applyHeightToLastDescent:
false
,
);
await
tester
.
pumpWidget
(
boilerplate
(
child:
const
SelectableText
(
text
),
),
);
expect
(
findRenderEditable
(
tester
).
textHeightBehavior
,
isNull
);
await
tester
.
pumpWidget
(
boilerplate
(
child:
const
SelectableText
(
text
,
textHeightBehavior:
textHeightBehavior
,
),
),
);
expect
(
findRenderEditable
(
tester
).
textHeightBehavior
,
textHeightBehavior
);
});
testWidgets
(
'Cursor blinks when showCursor is true'
,
(
WidgetTester
tester
)
async
{
testWidgets
(
'Cursor blinks when showCursor is true'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
await
tester
.
pumpWidget
(
overlay
(
overlay
(
...
...
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