From 0404382f4464190749d8cc384f6f9288160f9401 Mon Sep 17 00:00:00 2001 From: Hans Muller Date: Mon, 18 May 2020 22:19:01 -0700 Subject: [PATCH] Update deprecated TextTheme TextStyle references (#222) --- .../flutter_markdown/lib/src/style_sheet.dart | 58 +++++++++---------- .../test/flutter_markdown_test.dart | 38 ++++++------ 2 files changed, 48 insertions(+), 48 deletions(-) diff --git a/packages/flutter_markdown/lib/src/style_sheet.dart b/packages/flutter_markdown/lib/src/style_sheet.dart index 5f66e0ec8e..71c62945ec 100644 --- a/packages/flutter_markdown/lib/src/style_sheet.dart +++ b/packages/flutter_markdown/lib/src/style_sheet.dart @@ -76,34 +76,34 @@ class MarkdownStyleSheet { /// Creates a [MarkdownStyleSheet] from the [TextStyle]s in the provided [ThemeData]. factory MarkdownStyleSheet.fromTheme(ThemeData theme) { - assert(theme?.textTheme?.body1?.fontSize != null); + assert(theme?.textTheme?.bodyText2?.fontSize != null); return MarkdownStyleSheet( a: const TextStyle(color: Colors.blue), - p: theme.textTheme.body1, - code: theme.textTheme.body1.copyWith( + p: theme.textTheme.bodyText2, + code: theme.textTheme.bodyText2.copyWith( backgroundColor: theme.cardTheme?.color ?? theme.cardColor, fontFamily: "monospace", - fontSize: theme.textTheme.body1.fontSize * 0.85, + fontSize: theme.textTheme.bodyText2.fontSize * 0.85, ), - h1: theme.textTheme.headline, - h2: theme.textTheme.title, - h3: theme.textTheme.subhead, - h4: theme.textTheme.body2, - h5: theme.textTheme.body2, - h6: theme.textTheme.body2, + h1: theme.textTheme.headline5, + h2: theme.textTheme.headline6, + h3: theme.textTheme.subtitle1, + h4: theme.textTheme.bodyText1, + h5: theme.textTheme.bodyText1, + h6: theme.textTheme.bodyText1, em: const TextStyle(fontStyle: FontStyle.italic), strong: const TextStyle(fontWeight: FontWeight.bold), del: const TextStyle(decoration: TextDecoration.lineThrough), - blockquote: theme.textTheme.body1, - img: theme.textTheme.body1, - checkbox: theme.textTheme.body1.copyWith( + blockquote: theme.textTheme.bodyText2, + img: theme.textTheme.bodyText2, + checkbox: theme.textTheme.bodyText2.copyWith( color: theme.primaryColor, ), blockSpacing: 8.0, listIndent: 24.0, - listBullet: theme.textTheme.body1, + listBullet: theme.textTheme.bodyText2, tableHead: const TextStyle(fontWeight: FontWeight.w600), - tableBody: theme.textTheme.body1, + tableBody: theme.textTheme.bodyText2, tableHeadAlign: TextAlign.center, tableBorder: TableBorder.all( color: theme.dividerColor, @@ -243,31 +243,31 @@ class MarkdownStyleSheet { factory MarkdownStyleSheet.largeFromTheme(ThemeData theme) { return MarkdownStyleSheet( a: const TextStyle(color: Colors.blue), - p: theme.textTheme.body1, - code: theme.textTheme.body1.copyWith( + p: theme.textTheme.bodyText2, + code: theme.textTheme.bodyText2.copyWith( backgroundColor: theme.cardTheme?.color ?? theme.cardColor, fontFamily: "monospace", - fontSize: theme.textTheme.body1.fontSize * 0.85, + fontSize: theme.textTheme.bodyText2.fontSize * 0.85, ), - h1: theme.textTheme.display3, - h2: theme.textTheme.display2, - h3: theme.textTheme.display1, - h4: theme.textTheme.headline, - h5: theme.textTheme.title, - h6: theme.textTheme.subhead, + h1: theme.textTheme.headline2, + h2: theme.textTheme.headline3, + h3: theme.textTheme.headline4, + h4: theme.textTheme.headline5, + h5: theme.textTheme.headline6, + h6: theme.textTheme.subtitle1, em: const TextStyle(fontStyle: FontStyle.italic), strong: const TextStyle(fontWeight: FontWeight.bold), del: const TextStyle(decoration: TextDecoration.lineThrough), - blockquote: theme.textTheme.body1, - img: theme.textTheme.body1, - checkbox: theme.textTheme.body1.copyWith( + blockquote: theme.textTheme.bodyText2, + img: theme.textTheme.bodyText2, + checkbox: theme.textTheme.bodyText2.copyWith( color: theme.primaryColor, ), blockSpacing: 8.0, listIndent: 24.0, - listBullet: theme.textTheme.body1, + listBullet: theme.textTheme.bodyText2, tableHead: const TextStyle(fontWeight: FontWeight.w600), - tableBody: theme.textTheme.body1, + tableBody: theme.textTheme.bodyText2, tableHeadAlign: TextAlign.center, tableBorder: TableBorder.all( color: theme.dividerColor, diff --git a/packages/flutter_markdown/test/flutter_markdown_test.dart b/packages/flutter_markdown/test/flutter_markdown_test.dart index 055ef9a2ab..bbc65970c2 100644 --- a/packages/flutter_markdown/test/flutter_markdown_test.dart +++ b/packages/flutter_markdown/test/flutter_markdown_test.dart @@ -15,9 +15,9 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:mockito/mockito.dart'; void main() { - TextTheme textTheme = Typography(platform: TargetPlatform.android) + final TextTheme textTheme = Typography.material2018(platform: TargetPlatform.android) .black - .merge(TextTheme(body1: TextStyle(fontSize: 12.0))); + .merge(TextTheme(bodyText2: TextStyle(fontSize: 12.0))); testWidgets('Simple string', (WidgetTester tester) async { await tester.pumpWidget(_boilerplate(const MarkdownBody(data: 'Hello'))); @@ -758,7 +758,7 @@ void main() { testWidgets('MarkdownStyleSheet.fromTheme', (WidgetTester tester) async { final theme = ThemeData.dark().copyWith( textTheme: TextTheme( - body1: TextStyle(fontSize: 12.0), + bodyText2: TextStyle(fontSize: 12.0), ), ); @@ -768,59 +768,59 @@ void main() { expect(style.a.color, Colors.blue); // p - expect(style.p, theme.textTheme.body1); + expect(style.p, theme.textTheme.bodyText2); // code - expect(style.code.color, theme.textTheme.body1.color); - expect(style.code.fontSize, theme.textTheme.body1.fontSize * 0.85); + expect(style.code.color, theme.textTheme.bodyText2.color); + expect(style.code.fontSize, theme.textTheme.bodyText2.fontSize * 0.85); expect(style.code.fontFamily, 'monospace'); expect(style.code.backgroundColor, theme.cardColor); // H1 - expect(style.h1, theme.textTheme.headline); + expect(style.h1, theme.textTheme.headline5); // H2 - expect(style.h2, theme.textTheme.title); + expect(style.h2, theme.textTheme.headline6); // H3 - expect(style.h3, theme.textTheme.subhead); + expect(style.h3, theme.textTheme.subtitle1); // H4 - expect(style.h4, theme.textTheme.body2); + expect(style.h4, theme.textTheme.bodyText1); // H5 - expect(style.h5, theme.textTheme.body2); + expect(style.h5, theme.textTheme.bodyText1); // H6 - expect(style.h6, theme.textTheme.body2); + expect(style.h6, theme.textTheme.bodyText1); // em expect(style.em.fontStyle, FontStyle.italic); - expect(style.em.color, theme.textTheme.body1.color); + expect(style.em.color, theme.textTheme.bodyText2.color); // strong expect(style.strong.fontWeight, FontWeight.bold); - expect(style.strong.color, theme.textTheme.body1.color); + expect(style.strong.color, theme.textTheme.bodyText2.color); // del expect(style.del.decoration, TextDecoration.lineThrough); - expect(style.del.color, theme.textTheme.body1.color); + expect(style.del.color, theme.textTheme.bodyText2.color); // blockqoute - expect(style.blockquote, theme.textTheme.body1); + expect(style.blockquote, theme.textTheme.bodyText2); // img - expect(style.img, theme.textTheme.body1); + expect(style.img, theme.textTheme.bodyText2); // checkbox expect(style.checkbox.color, theme.primaryColor); - expect(style.checkbox.fontSize, theme.textTheme.body1.fontSize); + expect(style.checkbox.fontSize, theme.textTheme.bodyText2.fontSize); // tableHead expect(style.tableHead.fontWeight, FontWeight.w600); // tableBody - expect(style.tableBody, theme.textTheme.body1); + expect(style.tableBody, theme.textTheme.bodyText2); }); testWidgets('merge', (WidgetTester tester) async {