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].
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,

View File

@ -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 {