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
28f17d34
Unverified
Commit
28f17d34
authored
Mar 21, 2023
by
Dan Field
Committed by
GitHub
Mar 21, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make EditableText respect MediaQuery.boldTextOf (#122754)
parent
6b7c60d6
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
83 additions
and
19 deletions
+83
-19
selectable_text.dart
packages/flutter/lib/src/material/selectable_text.dart
+0
-3
editable_text.dart
packages/flutter/lib/src/widgets/editable_text.dart
+22
-16
editable_text_test.dart
packages/flutter/test/widgets/editable_text_test.dart
+61
-0
No files found.
packages/flutter/lib/src/material/selectable_text.dart
View file @
28f17d34
...
@@ -677,9 +677,6 @@ class _SelectableTextState extends State<SelectableText> implements TextSelectio
...
@@ -677,9 +677,6 @@ class _SelectableTextState extends State<SelectableText> implements TextSelectio
if
(
effectiveTextStyle
==
null
||
effectiveTextStyle
.
inherit
)
{
if
(
effectiveTextStyle
==
null
||
effectiveTextStyle
.
inherit
)
{
effectiveTextStyle
=
defaultTextStyle
.
style
.
merge
(
widget
.
style
??
_controller
.
_textSpan
.
style
);
effectiveTextStyle
=
defaultTextStyle
.
style
.
merge
(
widget
.
style
??
_controller
.
_textSpan
.
style
);
}
}
if
(
MediaQuery
.
boldTextOf
(
context
))
{
effectiveTextStyle
=
effectiveTextStyle
.
merge
(
const
TextStyle
(
fontWeight:
FontWeight
.
bold
));
}
final
Widget
child
=
RepaintBoundary
(
final
Widget
child
=
RepaintBoundary
(
child:
EditableText
(
child:
EditableText
(
key:
editableTextKey
,
key:
editableTextKey
,
...
...
packages/flutter/lib/src/widgets/editable_text.dart
View file @
28f17d34
...
@@ -2084,6 +2084,7 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
...
@@ -2084,6 +2084,7 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
AutofillClient
get
_effectiveAutofillClient
=>
widget
.
autofillClient
??
this
;
AutofillClient
get
_effectiveAutofillClient
=>
widget
.
autofillClient
??
this
;
late
SpellCheckConfiguration
_spellCheckConfiguration
;
late
SpellCheckConfiguration
_spellCheckConfiguration
;
late
TextStyle
_style
;
/// Configuration that determines how spell check will be performed.
/// Configuration that determines how spell check will be performed.
///
///
...
@@ -2589,6 +2590,10 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
...
@@ -2589,6 +2590,10 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
void
didChangeDependencies
()
{
void
didChangeDependencies
()
{
super
.
didChangeDependencies
();
super
.
didChangeDependencies
();
_style
=
MediaQuery
.
boldTextOf
(
context
)
?
widget
.
style
.
merge
(
const
TextStyle
(
fontWeight:
FontWeight
.
bold
))
:
widget
.
style
;
final
AutofillGroupState
?
newAutofillGroup
=
AutofillGroup
.
maybeOf
(
context
);
final
AutofillGroupState
?
newAutofillGroup
=
AutofillGroup
.
maybeOf
(
context
);
if
(
currentAutofillScope
!=
newAutofillGroup
)
{
if
(
currentAutofillScope
!=
newAutofillGroup
)
{
_currentAutofillScope
?.
unregister
(
autofillId
);
_currentAutofillScope
?.
unregister
(
autofillId
);
...
@@ -2682,14 +2687,16 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
...
@@ -2682,14 +2687,16 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
}
}
if
(
widget
.
style
!=
oldWidget
.
style
)
{
if
(
widget
.
style
!=
oldWidget
.
style
)
{
final
TextStyle
style
=
widget
.
style
;
// The _textInputConnection will pick up the new style when it attaches in
// The _textInputConnection will pick up the new style when it attaches in
// _openInputConnection.
// _openInputConnection.
_style
=
MediaQuery
.
boldTextOf
(
context
)
?
widget
.
style
.
merge
(
const
TextStyle
(
fontWeight:
FontWeight
.
bold
))
:
widget
.
style
;
if
(
_hasInputConnection
)
{
if
(
_hasInputConnection
)
{
_textInputConnection
!.
setStyle
(
_textInputConnection
!.
setStyle
(
fontFamily:
style
.
fontFamily
,
fontFamily:
_
style
.
fontFamily
,
fontSize:
style
.
fontSize
,
fontSize:
_
style
.
fontSize
,
fontWeight:
style
.
fontWeight
,
fontWeight:
_
style
.
fontWeight
,
textDirection:
_textDirection
,
textDirection:
_textDirection
,
textAlign:
widget
.
textAlign
,
textAlign:
widget
.
textAlign
,
);
);
...
@@ -3154,12 +3161,11 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
...
@@ -3154,12 +3161,11 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
:
TextInput
.
attach
(
this
,
_effectiveAutofillClient
.
textInputConfiguration
);
:
TextInput
.
attach
(
this
,
_effectiveAutofillClient
.
textInputConfiguration
);
_updateSizeAndTransform
();
_updateSizeAndTransform
();
_schedulePeriodicPostFrameCallbacks
();
_schedulePeriodicPostFrameCallbacks
();
final
TextStyle
style
=
widget
.
style
;
_textInputConnection
!
_textInputConnection
!
..
setStyle
(
..
setStyle
(
fontFamily:
style
.
fontFamily
,
fontFamily:
_
style
.
fontFamily
,
fontSize:
style
.
fontSize
,
fontSize:
_
style
.
fontSize
,
fontWeight:
style
.
fontWeight
,
fontWeight:
_
style
.
fontWeight
,
textDirection:
_textDirection
,
textDirection:
_textDirection
,
textAlign:
widget
.
textAlign
,
textAlign:
widget
.
textAlign
,
)
)
...
@@ -3222,13 +3228,12 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
...
@@ -3222,13 +3228,12 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
??
TextInput
.
attach
(
this
,
_effectiveAutofillClient
.
textInputConfiguration
);
??
TextInput
.
attach
(
this
,
_effectiveAutofillClient
.
textInputConfiguration
);
_textInputConnection
=
newConnection
;
_textInputConnection
=
newConnection
;
final
TextStyle
style
=
widget
.
style
;
newConnection
newConnection
..
show
()
..
show
()
..
setStyle
(
..
setStyle
(
fontFamily:
style
.
fontFamily
,
fontFamily:
_
style
.
fontFamily
,
fontSize:
style
.
fontSize
,
fontSize:
_
style
.
fontSize
,
fontWeight:
style
.
fontWeight
,
fontWeight:
_
style
.
fontWeight
,
textDirection:
_textDirection
,
textDirection:
_textDirection
,
textAlign:
widget
.
textAlign
,
textAlign:
widget
.
textAlign
,
)
)
...
@@ -4636,6 +4641,7 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
...
@@ -4636,6 +4641,7 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
/// By default makes text in composing range appear as underlined.
/// By default makes text in composing range appear as underlined.
/// Descendants can override this method to customize appearance of text.
/// Descendants can override this method to customize appearance of text.
TextSpan
buildTextSpan
()
{
TextSpan
buildTextSpan
()
{
if
(
widget
.
obscureText
)
{
if
(
widget
.
obscureText
)
{
String
text
=
_value
.
text
;
String
text
=
_value
.
text
;
text
=
widget
.
obscuringCharacter
*
text
.
length
;
text
=
widget
.
obscuringCharacter
*
text
.
length
;
...
@@ -4653,7 +4659,7 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
...
@@ -4653,7 +4659,7 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
text
=
text
.
replaceRange
(
o
,
o
+
1
,
_value
.
text
.
substring
(
o
,
o
+
1
));
text
=
text
.
replaceRange
(
o
,
o
+
1
,
_value
.
text
.
substring
(
o
,
o
+
1
));
}
}
}
}
return
TextSpan
(
style:
widget
.
style
,
text:
text
);
return
TextSpan
(
style:
_
style
,
text:
text
);
}
}
if
(
_placeholderLocation
>=
0
&&
_placeholderLocation
<=
_value
.
text
.
length
)
{
if
(
_placeholderLocation
>=
0
&&
_placeholderLocation
<=
_value
.
text
.
length
)
{
final
List
<
_ScribblePlaceholder
>
placeholders
=
<
_ScribblePlaceholder
>[];
final
List
<
_ScribblePlaceholder
>
placeholders
=
<
_ScribblePlaceholder
>[];
...
@@ -4665,7 +4671,7 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
...
@@ -4665,7 +4671,7 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
}
else
{
}
else
{
placeholders
.
add
(
const
_ScribblePlaceholder
(
child:
SizedBox
.
shrink
(),
size:
Size
(
100.0
,
0.0
)));
placeholders
.
add
(
const
_ScribblePlaceholder
(
child:
SizedBox
.
shrink
(),
size:
Size
(
100.0
,
0.0
)));
}
}
return
TextSpan
(
style:
widget
.
style
,
children:
<
InlineSpan
>[
return
TextSpan
(
style:
_
style
,
children:
<
InlineSpan
>[
TextSpan
(
text:
_value
.
text
.
substring
(
0
,
placeholderLocation
)),
TextSpan
(
text:
_value
.
text
.
substring
(
0
,
placeholderLocation
)),
...
placeholders
,
...
placeholders
,
TextSpan
(
text:
_value
.
text
.
substring
(
placeholderLocation
)),
TextSpan
(
text:
_value
.
text
.
substring
(
placeholderLocation
)),
...
@@ -4684,7 +4690,7 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
...
@@ -4684,7 +4690,7 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
return
buildTextSpanWithSpellCheckSuggestions
(
return
buildTextSpanWithSpellCheckSuggestions
(
_value
,
_value
,
composingRegionOutOfRange
,
composingRegionOutOfRange
,
widget
.
style
,
_
style
,
_spellCheckConfiguration
.
misspelledTextStyle
!,
_spellCheckConfiguration
.
misspelledTextStyle
!,
spellCheckResults
!,
spellCheckResults
!,
);
);
...
@@ -4693,7 +4699,7 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
...
@@ -4693,7 +4699,7 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
// Read only mode should not paint text composing.
// Read only mode should not paint text composing.
return
widget
.
controller
.
buildTextSpan
(
return
widget
.
controller
.
buildTextSpan
(
context:
context
,
context:
context
,
style:
widget
.
style
,
style:
_
style
,
withComposing:
withComposing
,
withComposing:
withComposing
,
);
);
}
}
...
...
packages/flutter/test/widgets/editable_text_test.dart
View file @
28f17d34
...
@@ -5374,6 +5374,46 @@ void main() {
...
@@ -5374,6 +5374,46 @@ void main() {
);
);
});
});
testWidgets
(
'text styling info is sent on show keyboard (bold override)'
,
(
WidgetTester
tester
)
async
{
final
List
<
MethodCall
>
log
=
<
MethodCall
>[];
tester
.
binding
.
defaultBinaryMessenger
.
setMockMethodCallHandler
(
SystemChannels
.
textInput
,
(
MethodCall
methodCall
)
async
{
log
.
add
(
methodCall
);
return
null
;
});
final
TextEditingController
controller
=
TextEditingController
();
await
tester
.
pumpWidget
(
MediaQuery
(
data:
const
MediaQueryData
(
boldText:
true
),
child:
EditableText
(
textDirection:
TextDirection
.
rtl
,
controller:
controller
,
focusNode:
FocusNode
(),
style:
const
TextStyle
(
fontSize:
20.0
,
fontFamily:
'Roboto'
,
fontWeight:
FontWeight
.
w600
,
),
cursorColor:
Colors
.
blue
,
backgroundCursorColor:
Colors
.
grey
,
),
),
);
await
tester
.
showKeyboard
(
find
.
byType
(
EditableText
));
final
MethodCall
setStyle
=
log
.
firstWhere
((
MethodCall
m
)
=>
m
.
method
==
'TextInput.setStyle'
);
expect
(
setStyle
,
isMethodCall
(
'TextInput.setStyle'
,
arguments:
<
String
,
dynamic
>{
'fontSize'
:
20.0
,
'fontFamily'
:
'Roboto'
,
'fontWeightIndex'
:
FontWeight
.
bold
.
index
,
'textAlignIndex'
:
4
,
'textDirectionIndex'
:
0
,
}),
);
});
testWidgets
(
'text styling info is sent on style update'
,
(
WidgetTester
tester
)
async
{
testWidgets
(
'text styling info is sent on style update'
,
(
WidgetTester
tester
)
async
{
final
GlobalKey
<
EditableTextState
>
editableTextKey
=
GlobalKey
<
EditableTextState
>();
final
GlobalKey
<
EditableTextState
>
editableTextKey
=
GlobalKey
<
EditableTextState
>();
late
StateSetter
setState
;
late
StateSetter
setState
;
...
@@ -15519,6 +15559,27 @@ testWidgets('Floating cursor ending with selection', (WidgetTester tester) async
...
@@ -15519,6 +15559,27 @@ testWidgets('Floating cursor ending with selection', (WidgetTester tester) async
skip:
!
kIsWeb
,
// [intended]
skip:
!
kIsWeb
,
// [intended]
);
);
});
});
testWidgets
(
'EditableText respects MediaQuery.boldText'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
Directionality
(
textDirection:
TextDirection
.
ltr
,
child:
MediaQuery
(
data:
const
MediaQueryData
(
boldText:
true
),
child:
EditableText
(
controller:
controller
,
focusNode:
focusNode
,
style:
const
TextStyle
(
fontWeight:
FontWeight
.
normal
),
cursorColor:
Colors
.
red
,
backgroundCursorColor:
Colors
.
green
,
),
),
));
controller
.
text
=
'foo'
;
final
EditableTextState
state
=
tester
.
state
<
EditableTextState
>(
find
.
byType
(
EditableText
));
expect
(
state
.
buildTextSpan
().
style
!.
fontWeight
,
FontWeight
.
bold
);
});
}
}
class
UnsettableController
extends
TextEditingController
{
class
UnsettableController
extends
TextEditingController
{
...
...
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