Apply segment label colour changes to the painted text
A colour-only style change (selected, unselected or disabled) only scheduled a repaint, but the text painter takes its style during layout, so the label kept its old colour until something else caused a layout. Request layout for every style change.
This commit is contained in:
1 parent
6daa85edae
commit
b276b9daf3
2 files changed
+28
-3
No files matched your search
@@ -893,12 +893,15 @@ class _RenderSegmentLabel extends RenderBox {
|
||||
TextStyle _style;
|
||||
set style(TextStyle value) {
|
||||
if (value == _style) return;
|
||||
final relayout =
|
||||
value.compareTo(_style).index > RenderComparison.paint.index;
|
||||
_style = value;
|
||||
relayout ? markNeedsLayout() : markNeedsPaint();
|
||||
// Layout even for a colour-only change: the painter takes the new style
|
||||
// (the selected or disabled colour) in _fit, not in paint.
|
||||
markNeedsLayout();
|
||||
}
|
||||
|
||||
@visibleForTesting
|
||||
Color? get debugPaintedColor => _painter.text?.style?.color;
|
||||
|
||||
TextScaler _textScaler;
|
||||
set textScaler(TextScaler value) {
|
||||
if (value == _textScaler) return;
|
||||
|
||||
@@ -54,4 +54,26 @@ void main() {
|
||||
expect(box.size.width, lessThanOrEqualTo(parent.size.width));
|
||||
}
|
||||
});
|
||||
|
||||
testWidgets('a colour-only style change reaches the painted text', (
|
||||
tester,
|
||||
) async {
|
||||
Widget label(Color color) => MaterialApp(
|
||||
home: Center(
|
||||
child: DefaultTextStyle(
|
||||
style: TextStyle(fontSize: 14, color: color),
|
||||
child: const MeshSegmentLabel('Flood'),
|
||||
),
|
||||
),
|
||||
);
|
||||
Color? painted() =>
|
||||
(tester.renderObject(find.byType(MeshSegmentLabel)) as dynamic)
|
||||
.debugPaintedColor
|
||||
as Color?;
|
||||
|
||||
await tester.pumpWidget(label(const Color(0xFF112233)));
|
||||
expect(painted(), const Color(0xFF112233));
|
||||
await tester.pumpWidget(label(const Color(0xFFEEDDCC)));
|
||||
expect(painted(), const Color(0xFFEEDDCC));
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user