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
4901744e
Unverified
Commit
4901744e
authored
Jan 05, 2021
by
Jesse
Committed by
GitHub
Jan 05, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add BuildContext parameter to TextEditingController.buildTextSpan (#72344)
parent
3fd3447f
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
2 deletions
+32
-2
selectable_text.dart
packages/flutter/lib/src/material/selectable_text.dart
+1
-1
editable_text.dart
packages/flutter/lib/src/widgets/editable_text.dart
+2
-1
editable_text_test.dart
packages/flutter/test/widgets/editable_text_test.dart
+29
-0
No files found.
packages/flutter/lib/src/material/selectable_text.dart
View file @
4901744e
...
...
@@ -31,7 +31,7 @@ class _TextSpanEditingController extends TextEditingController {
final
TextSpan
_textSpan
;
@override
TextSpan
buildTextSpan
({
TextStyle
?
style
,
bool
?
withComposing
})
{
TextSpan
buildTextSpan
({
TextStyle
?
style
,
required
bool
withComposing
,
required
BuildContext
context
})
{
// This does not care about composing.
return
TextSpan
(
style:
style
,
...
...
packages/flutter/lib/src/widgets/editable_text.dart
View file @
4901744e
...
...
@@ -185,7 +185,7 @@ class TextEditingController extends ValueNotifier<TextEditingValue> {
///
/// By default makes text in composing range appear as underlined. Descendants
/// can override this method to customize appearance of text.
TextSpan
buildTextSpan
({
TextStyle
?
style
,
required
bool
withComposing
})
{
TextSpan
buildTextSpan
({
TextStyle
?
style
,
required
bool
withComposing
,
required
BuildContext
context
})
{
assert
(!
value
.
composing
.
isValid
||
!
withComposing
||
value
.
isComposingRangeValid
);
// If the composing range is out of range for the current text, ignore it to
// preserve the tree integrity, otherwise in release mode a RangeError will
...
...
@@ -2669,6 +2669,7 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
return
widget
.
controller
.
buildTextSpan
(
style:
widget
.
style
,
withComposing:
!
widget
.
readOnly
,
context:
context
,
);
}
}
...
...
packages/flutter/test/widgets/editable_text_test.dart
View file @
4901744e
...
...
@@ -5674,6 +5674,25 @@ void main() {
}),
);
});
testWidgets
(
'TextEditingController.buildTextSpan receives build context'
,
(
WidgetTester
tester
)
async
{
final
_AccentColorTextEditingController
controller
=
_AccentColorTextEditingController
(
'a'
);
const
Color
color
=
Color
.
fromARGB
(
255
,
1
,
2
,
3
);
await
tester
.
pumpWidget
(
MaterialApp
(
theme:
ThemeData
.
light
().
copyWith
(
accentColor:
color
),
home:
EditableText
(
controller:
controller
,
focusNode:
FocusNode
(),
style:
Typography
.
material2018
(
platform:
TargetPlatform
.
android
).
black
.
subtitle1
!,
cursorColor:
Colors
.
blue
,
backgroundCursorColor:
Colors
.
grey
,
),
));
final
RenderEditable
renderEditable
=
findRenderEditable
(
tester
);
final
TextSpan
textSpan
=
renderEditable
.
text
!;
expect
(
textSpan
.
style
!.
color
,
color
);
});
});
testWidgets
(
'autofocus:true on first frame does not throw'
,
(
WidgetTester
tester
)
async
{
...
...
@@ -7109,3 +7128,13 @@ class SkipPaintingRenderObject extends RenderProxyBox {
@override
void
paint
(
PaintingContext
context
,
Offset
offset
)
{
}
}
class
_AccentColorTextEditingController
extends
TextEditingController
{
_AccentColorTextEditingController
(
String
text
)
:
super
(
text:
text
);
@override
TextSpan
buildTextSpan
({
TextStyle
?
style
,
required
bool
withComposing
,
required
BuildContext
context
})
{
final
Color
color
=
Theme
.
of
(
context
).
accentColor
;
return
super
.
buildTextSpan
(
style:
TextStyle
(
color:
color
),
withComposing:
withComposing
,
context:
context
);
}
}
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