Unverified Commit b96ae03b authored by Michael Goderbauer's avatar Michael Goderbauer Committed by GitHub

Add backgroundColor argument to TextStyle for convenience (#28172)

parent 6f5e88a5
......@@ -666,6 +666,7 @@ class _TextStyleProxy implements TextStyle {
// Do make sure that all the properties correctly forward to the _delegate.
@override Color get color => _delegate.color;
@override Color get backgroundColor => _delegate.backgroundColor;
@override String get debugLabel => _delegate.debugLabel;
@override TextDecoration get decoration => _delegate.decoration;
@override Color get decorationColor => _delegate.decorationColor;
......@@ -700,7 +701,7 @@ class _TextStyleProxy implements TextStyle {
}
@override
TextStyle apply({ Color color, TextDecoration decoration, Color decorationColor, TextDecorationStyle decorationStyle, String fontFamily, List<String> fontFamilyFallback, double fontSizeFactor = 1.0, double fontSizeDelta = 0.0, int fontWeightDelta = 0, double letterSpacingFactor = 1.0, double letterSpacingDelta = 0.0, double wordSpacingFactor = 1.0, double wordSpacingDelta = 0.0, double heightFactor = 1.0, double heightDelta = 0.0 }) {
TextStyle apply({ Color color, Color backgroundColor, TextDecoration decoration, Color decorationColor, TextDecorationStyle decorationStyle, String fontFamily, List<String> fontFamilyFallback, double fontSizeFactor = 1.0, double fontSizeDelta = 0.0, int fontWeightDelta = 0, double letterSpacingFactor = 1.0, double letterSpacingDelta = 0.0, double wordSpacingFactor = 1.0, double wordSpacingDelta = 0.0, double heightFactor = 1.0, double heightDelta = 0.0 }) {
throw UnimplementedError();
}
......@@ -710,7 +711,7 @@ class _TextStyleProxy implements TextStyle {
}
@override
TextStyle copyWith({ Color color, String fontFamily, List<String> fontFamilyFallback, double fontSize, FontWeight fontWeight, FontStyle fontStyle, double letterSpacing, double wordSpacing, TextBaseline textBaseline, double height, Locale locale, ui.Paint foreground, ui.Paint background, List<Shadow> shadows, TextDecoration decoration, Color decorationColor, TextDecorationStyle decorationStyle, String debugLabel }) {
TextStyle copyWith({ Color color, Color backgroundColor, String fontFamily, List<String> fontFamilyFallback, double fontSize, FontWeight fontWeight, FontStyle fontStyle, double letterSpacing, double wordSpacing, TextBaseline textBaseline, double height, Locale locale, ui.Paint foreground, ui.Paint background, List<Shadow> shadows, TextDecoration decoration, Color decorationColor, TextDecorationStyle decorationStyle, String debugLabel }) {
throw UnimplementedError();
}
......
......@@ -294,4 +294,58 @@ void main() {
expect(TextStyle.lerp(redPaintTextStyle, bluePaintTextStyle, .25).foreground.color, red);
expect(TextStyle.lerp(redPaintTextStyle, bluePaintTextStyle, .75).foreground.color, blue);
});
test('backgroundColor', () {
const TextStyle s1 = TextStyle();
expect(s1.backgroundColor, isNull);
expect(s1.toString(), 'TextStyle(<all styles inherited>)');
const TextStyle s2 = TextStyle(backgroundColor: Color(0xFF00FF00));
expect(s2.backgroundColor, const Color(0xFF00FF00));
expect(s2.toString(), 'TextStyle(inherit: true, backgroundColor: Color(0xff00ff00))');
final ui.TextStyle ts2 = s2.getTextStyle();
expect(ts2.toString(), contains('background: Paint(Color(0xff00ff00))'));
});
test('TextStyle background and backgroundColor combos', () {
const Color red = Color.fromARGB(255, 255, 0, 0);
const Color blue = Color.fromARGB(255, 0, 0, 255);
const TextStyle redTextStyle = TextStyle(backgroundColor: red);
const TextStyle blueTextStyle = TextStyle(backgroundColor: blue);
final TextStyle redPaintTextStyle = TextStyle(background: Paint()..color = red);
final TextStyle bluePaintTextStyle = TextStyle(background: Paint()..color = blue);
// merge/copyWith
final TextStyle redBlueBothForegroundMerged = redTextStyle.merge(blueTextStyle);
expect(redBlueBothForegroundMerged.backgroundColor, blue);
expect(redBlueBothForegroundMerged.foreground, isNull);
final TextStyle redBlueBothPaintMerged = redPaintTextStyle.merge(bluePaintTextStyle);
expect(redBlueBothPaintMerged.backgroundColor, null);
expect(redBlueBothPaintMerged.background, bluePaintTextStyle.background);
final TextStyle redPaintBlueColorMerged = redPaintTextStyle.merge(blueTextStyle);
expect(redPaintBlueColorMerged.backgroundColor, null);
expect(redPaintBlueColorMerged.background, redPaintTextStyle.background);
final TextStyle blueColorRedPaintMerged = blueTextStyle.merge(redPaintTextStyle);
expect(blueColorRedPaintMerged.backgroundColor, null);
expect(blueColorRedPaintMerged.background, redPaintTextStyle.background);
// apply
expect(redPaintTextStyle.apply(backgroundColor: blue).backgroundColor, isNull);
expect(redPaintTextStyle.apply(backgroundColor: blue).background.color, red);
expect(redTextStyle.apply(backgroundColor: blue).backgroundColor, blue);
// lerp
expect(TextStyle.lerp(redTextStyle, blueTextStyle, .25).backgroundColor, Color.lerp(red, blue, .25));
expect(TextStyle.lerp(redTextStyle, bluePaintTextStyle, .25).backgroundColor, isNull);
expect(TextStyle.lerp(redTextStyle, bluePaintTextStyle, .25).background.color, red);
expect(TextStyle.lerp(redTextStyle, bluePaintTextStyle, .75).background.color, blue);
expect(TextStyle.lerp(redPaintTextStyle, bluePaintTextStyle, .25).backgroundColor, isNull);
expect(TextStyle.lerp(redPaintTextStyle, bluePaintTextStyle, .25).background.color, red);
expect(TextStyle.lerp(redPaintTextStyle, bluePaintTextStyle, .75).background.color, blue);
});
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment