Update deprecated TextTheme TextStyle references (#222)

This commit is contained in:
Hans Muller
2020-05-18 22:19:01 -07:00
committed by GitHub
parent 2d6f76820a
commit 0404382f44
2 changed files with 48 additions and 48 deletions

View File

@ -76,34 +76,34 @@ class MarkdownStyleSheet {
/// Creates a [MarkdownStyleSheet] from the [TextStyle]s in the provided [ThemeData]. /// Creates a [MarkdownStyleSheet] from the [TextStyle]s in the provided [ThemeData].
factory MarkdownStyleSheet.fromTheme(ThemeData theme) { factory MarkdownStyleSheet.fromTheme(ThemeData theme) {
assert(theme?.textTheme?.body1?.fontSize != null); assert(theme?.textTheme?.bodyText2?.fontSize != null);
return MarkdownStyleSheet( return MarkdownStyleSheet(
a: const TextStyle(color: Colors.blue), a: const TextStyle(color: Colors.blue),
p: theme.textTheme.body1, p: theme.textTheme.bodyText2,
code: theme.textTheme.body1.copyWith( code: theme.textTheme.bodyText2.copyWith(
backgroundColor: theme.cardTheme?.color ?? theme.cardColor, backgroundColor: theme.cardTheme?.color ?? theme.cardColor,
fontFamily: "monospace", fontFamily: "monospace",
fontSize: theme.textTheme.body1.fontSize * 0.85, fontSize: theme.textTheme.bodyText2.fontSize * 0.85,
), ),
h1: theme.textTheme.headline, h1: theme.textTheme.headline5,
h2: theme.textTheme.title, h2: theme.textTheme.headline6,
h3: theme.textTheme.subhead, h3: theme.textTheme.subtitle1,
h4: theme.textTheme.body2, h4: theme.textTheme.bodyText1,
h5: theme.textTheme.body2, h5: theme.textTheme.bodyText1,
h6: theme.textTheme.body2, h6: theme.textTheme.bodyText1,
em: const TextStyle(fontStyle: FontStyle.italic), em: const TextStyle(fontStyle: FontStyle.italic),
strong: const TextStyle(fontWeight: FontWeight.bold), strong: const TextStyle(fontWeight: FontWeight.bold),
del: const TextStyle(decoration: TextDecoration.lineThrough), del: const TextStyle(decoration: TextDecoration.lineThrough),
blockquote: theme.textTheme.body1, blockquote: theme.textTheme.bodyText2,
img: theme.textTheme.body1, img: theme.textTheme.bodyText2,
checkbox: theme.textTheme.body1.copyWith( checkbox: theme.textTheme.bodyText2.copyWith(
color: theme.primaryColor, color: theme.primaryColor,
), ),
blockSpacing: 8.0, blockSpacing: 8.0,
listIndent: 24.0, listIndent: 24.0,
listBullet: theme.textTheme.body1, listBullet: theme.textTheme.bodyText2,
tableHead: const TextStyle(fontWeight: FontWeight.w600), tableHead: const TextStyle(fontWeight: FontWeight.w600),
tableBody: theme.textTheme.body1, tableBody: theme.textTheme.bodyText2,
tableHeadAlign: TextAlign.center, tableHeadAlign: TextAlign.center,
tableBorder: TableBorder.all( tableBorder: TableBorder.all(
color: theme.dividerColor, color: theme.dividerColor,
@ -243,31 +243,31 @@ class MarkdownStyleSheet {
factory MarkdownStyleSheet.largeFromTheme(ThemeData theme) { factory MarkdownStyleSheet.largeFromTheme(ThemeData theme) {
return MarkdownStyleSheet( return MarkdownStyleSheet(
a: const TextStyle(color: Colors.blue), a: const TextStyle(color: Colors.blue),
p: theme.textTheme.body1, p: theme.textTheme.bodyText2,
code: theme.textTheme.body1.copyWith( code: theme.textTheme.bodyText2.copyWith(
backgroundColor: theme.cardTheme?.color ?? theme.cardColor, backgroundColor: theme.cardTheme?.color ?? theme.cardColor,
fontFamily: "monospace", fontFamily: "monospace",
fontSize: theme.textTheme.body1.fontSize * 0.85, fontSize: theme.textTheme.bodyText2.fontSize * 0.85,
), ),
h1: theme.textTheme.display3, h1: theme.textTheme.headline2,
h2: theme.textTheme.display2, h2: theme.textTheme.headline3,
h3: theme.textTheme.display1, h3: theme.textTheme.headline4,
h4: theme.textTheme.headline, h4: theme.textTheme.headline5,
h5: theme.textTheme.title, h5: theme.textTheme.headline6,
h6: theme.textTheme.subhead, h6: theme.textTheme.subtitle1,
em: const TextStyle(fontStyle: FontStyle.italic), em: const TextStyle(fontStyle: FontStyle.italic),
strong: const TextStyle(fontWeight: FontWeight.bold), strong: const TextStyle(fontWeight: FontWeight.bold),
del: const TextStyle(decoration: TextDecoration.lineThrough), del: const TextStyle(decoration: TextDecoration.lineThrough),
blockquote: theme.textTheme.body1, blockquote: theme.textTheme.bodyText2,
img: theme.textTheme.body1, img: theme.textTheme.bodyText2,
checkbox: theme.textTheme.body1.copyWith( checkbox: theme.textTheme.bodyText2.copyWith(
color: theme.primaryColor, color: theme.primaryColor,
), ),
blockSpacing: 8.0, blockSpacing: 8.0,
listIndent: 24.0, listIndent: 24.0,
listBullet: theme.textTheme.body1, listBullet: theme.textTheme.bodyText2,
tableHead: const TextStyle(fontWeight: FontWeight.w600), tableHead: const TextStyle(fontWeight: FontWeight.w600),
tableBody: theme.textTheme.body1, tableBody: theme.textTheme.bodyText2,
tableHeadAlign: TextAlign.center, tableHeadAlign: TextAlign.center,
tableBorder: TableBorder.all( tableBorder: TableBorder.all(
color: theme.dividerColor, color: theme.dividerColor,

View File

@ -15,9 +15,9 @@ import 'package:flutter_test/flutter_test.dart';
import 'package:mockito/mockito.dart'; import 'package:mockito/mockito.dart';
void main() { void main() {
TextTheme textTheme = Typography(platform: TargetPlatform.android) final TextTheme textTheme = Typography.material2018(platform: TargetPlatform.android)
.black .black
.merge(TextTheme(body1: TextStyle(fontSize: 12.0))); .merge(TextTheme(bodyText2: TextStyle(fontSize: 12.0)));
testWidgets('Simple string', (WidgetTester tester) async { testWidgets('Simple string', (WidgetTester tester) async {
await tester.pumpWidget(_boilerplate(const MarkdownBody(data: 'Hello'))); await tester.pumpWidget(_boilerplate(const MarkdownBody(data: 'Hello')));
@ -758,7 +758,7 @@ void main() {
testWidgets('MarkdownStyleSheet.fromTheme', (WidgetTester tester) async { testWidgets('MarkdownStyleSheet.fromTheme', (WidgetTester tester) async {
final theme = ThemeData.dark().copyWith( final theme = ThemeData.dark().copyWith(
textTheme: TextTheme( textTheme: TextTheme(
body1: TextStyle(fontSize: 12.0), bodyText2: TextStyle(fontSize: 12.0),
), ),
); );
@ -768,59 +768,59 @@ void main() {
expect(style.a.color, Colors.blue); expect(style.a.color, Colors.blue);
// p // p
expect(style.p, theme.textTheme.body1); expect(style.p, theme.textTheme.bodyText2);
// code // code
expect(style.code.color, theme.textTheme.body1.color); expect(style.code.color, theme.textTheme.bodyText2.color);
expect(style.code.fontSize, theme.textTheme.body1.fontSize * 0.85); expect(style.code.fontSize, theme.textTheme.bodyText2.fontSize * 0.85);
expect(style.code.fontFamily, 'monospace'); expect(style.code.fontFamily, 'monospace');
expect(style.code.backgroundColor, theme.cardColor); expect(style.code.backgroundColor, theme.cardColor);
// H1 // H1
expect(style.h1, theme.textTheme.headline); expect(style.h1, theme.textTheme.headline5);
// H2 // H2
expect(style.h2, theme.textTheme.title); expect(style.h2, theme.textTheme.headline6);
// H3 // H3
expect(style.h3, theme.textTheme.subhead); expect(style.h3, theme.textTheme.subtitle1);
// H4 // H4
expect(style.h4, theme.textTheme.body2); expect(style.h4, theme.textTheme.bodyText1);
// H5 // H5
expect(style.h5, theme.textTheme.body2); expect(style.h5, theme.textTheme.bodyText1);
// H6 // H6
expect(style.h6, theme.textTheme.body2); expect(style.h6, theme.textTheme.bodyText1);
// em // em
expect(style.em.fontStyle, FontStyle.italic); expect(style.em.fontStyle, FontStyle.italic);
expect(style.em.color, theme.textTheme.body1.color); expect(style.em.color, theme.textTheme.bodyText2.color);
// strong // strong
expect(style.strong.fontWeight, FontWeight.bold); expect(style.strong.fontWeight, FontWeight.bold);
expect(style.strong.color, theme.textTheme.body1.color); expect(style.strong.color, theme.textTheme.bodyText2.color);
// del // del
expect(style.del.decoration, TextDecoration.lineThrough); expect(style.del.decoration, TextDecoration.lineThrough);
expect(style.del.color, theme.textTheme.body1.color); expect(style.del.color, theme.textTheme.bodyText2.color);
// blockqoute // blockqoute
expect(style.blockquote, theme.textTheme.body1); expect(style.blockquote, theme.textTheme.bodyText2);
// img // img
expect(style.img, theme.textTheme.body1); expect(style.img, theme.textTheme.bodyText2);
// checkbox // checkbox
expect(style.checkbox.color, theme.primaryColor); expect(style.checkbox.color, theme.primaryColor);
expect(style.checkbox.fontSize, theme.textTheme.body1.fontSize); expect(style.checkbox.fontSize, theme.textTheme.bodyText2.fontSize);
// tableHead // tableHead
expect(style.tableHead.fontWeight, FontWeight.w600); expect(style.tableHead.fontWeight, FontWeight.w600);
// tableBody // tableBody
expect(style.tableBody, theme.textTheme.body1); expect(style.tableBody, theme.textTheme.bodyText2);
}); });
testWidgets('merge', (WidgetTester tester) async { testWidgets('merge', (WidgetTester tester) async {