SelectableText.rich: Fix TextSpan.style not merged into default text style (#101911)
Properly merges the TextSpan.style of SelectableText.rich.
This commit is contained in:
@@ -664,7 +664,7 @@ class _SelectableTextState extends State<SelectableText> implements TextSelectio
|
||||
final DefaultTextStyle defaultTextStyle = DefaultTextStyle.of(context);
|
||||
TextStyle? effectiveTextStyle = widget.style;
|
||||
if (effectiveTextStyle == null || effectiveTextStyle.inherit) {
|
||||
effectiveTextStyle = defaultTextStyle.style.merge(widget.style);
|
||||
effectiveTextStyle = defaultTextStyle.style.merge(widget.style ?? _controller._textSpan.style);
|
||||
}
|
||||
if (MediaQuery.boldTextOverride(context)) {
|
||||
effectiveTextStyle = effectiveTextStyle.merge(const TextStyle(fontWeight: FontWeight.bold));
|
||||
|
||||
@@ -5052,4 +5052,24 @@ void main() {
|
||||
expect(find.text('Regular Text', skipOffstage: false), findsOneWidget);
|
||||
expect(find.byType(SelectableText, skipOffstage: false), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('SelectableText text span style is merged with default text style', (WidgetTester tester) async {
|
||||
// This is a regression test for https://github.com/flutter/flutter/issues/71389
|
||||
|
||||
const TextStyle textStyle = TextStyle(color: Color(0xff00ff00), fontSize: 12.0);
|
||||
|
||||
await tester.pumpWidget(
|
||||
const MaterialApp(
|
||||
home: SelectableText.rich(
|
||||
TextSpan(
|
||||
text: 'Abcd',
|
||||
style: textStyle,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
final EditableText editableText = tester.widget(find.byType(EditableText));
|
||||
expect(editableText.style.fontSize, textStyle.fontSize);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user