Unverified Commit 7a63fac0 authored by Hans Muller's avatar Hans Muller Committed by GitHub

TextTheme.apply() should not assume non-null TextStyle fields (#23184)

parent a0010d39
...@@ -331,7 +331,7 @@ class TextTheme extends Diagnosticable { ...@@ -331,7 +331,7 @@ class TextTheme extends Diagnosticable {
TextDecorationStyle decorationStyle, TextDecorationStyle decorationStyle,
}) { }) {
return TextTheme( return TextTheme(
display4: display4.apply( display4: display4?.apply(
color: displayColor, color: displayColor,
decoration: decoration, decoration: decoration,
decorationColor: decorationColor, decorationColor: decorationColor,
...@@ -340,7 +340,7 @@ class TextTheme extends Diagnosticable { ...@@ -340,7 +340,7 @@ class TextTheme extends Diagnosticable {
fontSizeFactor: fontSizeFactor, fontSizeFactor: fontSizeFactor,
fontSizeDelta: fontSizeDelta, fontSizeDelta: fontSizeDelta,
), ),
display3: display3.apply( display3: display3?.apply(
color: displayColor, color: displayColor,
decoration: decoration, decoration: decoration,
decorationColor: decorationColor, decorationColor: decorationColor,
...@@ -349,7 +349,7 @@ class TextTheme extends Diagnosticable { ...@@ -349,7 +349,7 @@ class TextTheme extends Diagnosticable {
fontSizeFactor: fontSizeFactor, fontSizeFactor: fontSizeFactor,
fontSizeDelta: fontSizeDelta, fontSizeDelta: fontSizeDelta,
), ),
display2: display2.apply( display2: display2?.apply(
color: displayColor, color: displayColor,
decoration: decoration, decoration: decoration,
decorationColor: decorationColor, decorationColor: decorationColor,
...@@ -358,7 +358,7 @@ class TextTheme extends Diagnosticable { ...@@ -358,7 +358,7 @@ class TextTheme extends Diagnosticable {
fontSizeFactor: fontSizeFactor, fontSizeFactor: fontSizeFactor,
fontSizeDelta: fontSizeDelta, fontSizeDelta: fontSizeDelta,
), ),
display1: display1.apply( display1: display1?.apply(
color: displayColor, color: displayColor,
decoration: decoration, decoration: decoration,
decorationColor: decorationColor, decorationColor: decorationColor,
...@@ -367,7 +367,7 @@ class TextTheme extends Diagnosticable { ...@@ -367,7 +367,7 @@ class TextTheme extends Diagnosticable {
fontSizeFactor: fontSizeFactor, fontSizeFactor: fontSizeFactor,
fontSizeDelta: fontSizeDelta, fontSizeDelta: fontSizeDelta,
), ),
headline: headline.apply( headline: headline?.apply(
color: bodyColor, color: bodyColor,
decoration: decoration, decoration: decoration,
decorationColor: decorationColor, decorationColor: decorationColor,
...@@ -376,7 +376,7 @@ class TextTheme extends Diagnosticable { ...@@ -376,7 +376,7 @@ class TextTheme extends Diagnosticable {
fontSizeFactor: fontSizeFactor, fontSizeFactor: fontSizeFactor,
fontSizeDelta: fontSizeDelta, fontSizeDelta: fontSizeDelta,
), ),
title: title.apply( title: title?.apply(
color: bodyColor, color: bodyColor,
decoration: decoration, decoration: decoration,
decorationColor: decorationColor, decorationColor: decorationColor,
...@@ -385,7 +385,7 @@ class TextTheme extends Diagnosticable { ...@@ -385,7 +385,7 @@ class TextTheme extends Diagnosticable {
fontSizeFactor: fontSizeFactor, fontSizeFactor: fontSizeFactor,
fontSizeDelta: fontSizeDelta, fontSizeDelta: fontSizeDelta,
), ),
subhead: subhead.apply( subhead: subhead?.apply(
color: bodyColor, color: bodyColor,
decoration: decoration, decoration: decoration,
decorationColor: decorationColor, decorationColor: decorationColor,
...@@ -394,7 +394,7 @@ class TextTheme extends Diagnosticable { ...@@ -394,7 +394,7 @@ class TextTheme extends Diagnosticable {
fontSizeFactor: fontSizeFactor, fontSizeFactor: fontSizeFactor,
fontSizeDelta: fontSizeDelta, fontSizeDelta: fontSizeDelta,
), ),
body2: body2.apply( body2: body2?.apply(
color: bodyColor, color: bodyColor,
decoration: decoration, decoration: decoration,
decorationColor: decorationColor, decorationColor: decorationColor,
...@@ -403,7 +403,7 @@ class TextTheme extends Diagnosticable { ...@@ -403,7 +403,7 @@ class TextTheme extends Diagnosticable {
fontSizeFactor: fontSizeFactor, fontSizeFactor: fontSizeFactor,
fontSizeDelta: fontSizeDelta, fontSizeDelta: fontSizeDelta,
), ),
body1: body1.apply( body1: body1?.apply(
color: bodyColor, color: bodyColor,
decoration: decoration, decoration: decoration,
decorationColor: decorationColor, decorationColor: decorationColor,
...@@ -412,7 +412,7 @@ class TextTheme extends Diagnosticable { ...@@ -412,7 +412,7 @@ class TextTheme extends Diagnosticable {
fontSizeFactor: fontSizeFactor, fontSizeFactor: fontSizeFactor,
fontSizeDelta: fontSizeDelta, fontSizeDelta: fontSizeDelta,
), ),
caption: caption.apply( caption: caption?.apply(
color: displayColor, color: displayColor,
decoration: decoration, decoration: decoration,
decorationColor: decorationColor, decorationColor: decorationColor,
...@@ -421,7 +421,7 @@ class TextTheme extends Diagnosticable { ...@@ -421,7 +421,7 @@ class TextTheme extends Diagnosticable {
fontSizeFactor: fontSizeFactor, fontSizeFactor: fontSizeFactor,
fontSizeDelta: fontSizeDelta, fontSizeDelta: fontSizeDelta,
), ),
button: button.apply( button: button?.apply(
color: bodyColor, color: bodyColor,
decoration: decoration, decoration: decoration,
decorationColor: decorationColor, decorationColor: decorationColor,
...@@ -430,7 +430,7 @@ class TextTheme extends Diagnosticable { ...@@ -430,7 +430,7 @@ class TextTheme extends Diagnosticable {
fontSizeFactor: fontSizeFactor, fontSizeFactor: fontSizeFactor,
fontSizeDelta: fontSizeDelta, fontSizeDelta: fontSizeDelta,
), ),
subtitle: subtitle.apply( subtitle: subtitle?.apply(
color: bodyColor, color: bodyColor,
decoration: decoration, decoration: decoration,
decorationColor: decorationColor, decorationColor: decorationColor,
...@@ -439,7 +439,7 @@ class TextTheme extends Diagnosticable { ...@@ -439,7 +439,7 @@ class TextTheme extends Diagnosticable {
fontSizeFactor: fontSizeFactor, fontSizeFactor: fontSizeFactor,
fontSizeDelta: fontSizeDelta, fontSizeDelta: fontSizeDelta,
), ),
overline: overline.apply( overline: overline?.apply(
color: bodyColor, color: bodyColor,
decoration: decoration, decoration: decoration,
decorationColor: decorationColor, decorationColor: decorationColor,
......
...@@ -6,11 +6,20 @@ import 'package:flutter/material.dart'; ...@@ -6,11 +6,20 @@ import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
void main() { void main() {
test('TextTheme copyWith apply, merge basics', () { test('TextTheme copyWith apply, merge basics with const TextTheme()', () {
expect(const TextTheme(), equals(const TextTheme().copyWith()));
expect(const TextTheme(), equals(const TextTheme().apply()));
expect(const TextTheme(), equals(const TextTheme().merge(null)));
expect(const TextTheme().hashCode, equals(const TextTheme().copyWith().hashCode));
expect(const TextTheme(), equals(const TextTheme().copyWith()));
});
test('TextTheme copyWith apply, merge basics with Typography.black', () {
final Typography typography = Typography(platform: TargetPlatform.android); final Typography typography = Typography(platform: TargetPlatform.android);
expect(typography.black, equals(typography.black.copyWith())); expect(typography.black, equals(typography.black.copyWith()));
expect(typography.black, equals(typography.black.apply())); expect(typography.black, equals(typography.black.apply()));
expect(typography.black, equals(typography.black.merge(null))); expect(typography.black, equals(typography.black.merge(null)));
expect(typography.black, equals(const TextTheme().merge(typography.black)));
expect(typography.black, equals(typography.black.merge(typography.black))); expect(typography.black, equals(typography.black.merge(typography.black)));
expect(typography.white, equals(typography.black.merge(typography.white))); expect(typography.white, equals(typography.black.merge(typography.white)));
expect(typography.black.hashCode, equals(typography.black.copyWith().hashCode)); expect(typography.black.hashCode, equals(typography.black.copyWith().hashCode));
......
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