mirror of
https://github.com/flutter/packages.git
synced 2025-07-03 17:18:22 +08:00
Bugfixes for MarkdownStyleSheet and textScaleFactor (#243)
This commit is contained in:
@ -1,3 +1,8 @@
|
|||||||
|
## 0.4.3
|
||||||
|
|
||||||
|
* Fix merging of `MarkdownStyleSheets`
|
||||||
|
* Fix if not provided in `MarkdownStyleSheet` textScaleFactor uses default value of 1.0 instead using the textScaleFactor of the nearest MediaQuery
|
||||||
|
|
||||||
## 0.4.2
|
## 0.4.2
|
||||||
|
|
||||||
* Fix parsing of image caption & alt attributes
|
* Fix parsing of image caption & alt attributes
|
||||||
|
@ -43,17 +43,25 @@ final MarkdownStyleSheet Function(BuildContext, MarkdownStyleSheetBaseTheme)
|
|||||||
BuildContext context,
|
BuildContext context,
|
||||||
MarkdownStyleSheetBaseTheme baseTheme,
|
MarkdownStyleSheetBaseTheme baseTheme,
|
||||||
) {
|
) {
|
||||||
|
MarkdownStyleSheet result;
|
||||||
switch (baseTheme) {
|
switch (baseTheme) {
|
||||||
case MarkdownStyleSheetBaseTheme.platform:
|
case MarkdownStyleSheetBaseTheme.platform:
|
||||||
return (Platform.isIOS || Platform.isMacOS)
|
result = (Platform.isIOS || Platform.isMacOS)
|
||||||
? MarkdownStyleSheet.fromCupertinoTheme(CupertinoTheme.of(context))
|
? MarkdownStyleSheet.fromCupertinoTheme(CupertinoTheme.of(context))
|
||||||
: MarkdownStyleSheet.fromTheme(Theme.of(context));
|
: MarkdownStyleSheet.fromTheme(Theme.of(context));
|
||||||
|
break;
|
||||||
case MarkdownStyleSheetBaseTheme.cupertino:
|
case MarkdownStyleSheetBaseTheme.cupertino:
|
||||||
return MarkdownStyleSheet.fromCupertinoTheme(CupertinoTheme.of(context));
|
result =
|
||||||
|
MarkdownStyleSheet.fromCupertinoTheme(CupertinoTheme.of(context));
|
||||||
|
break;
|
||||||
case MarkdownStyleSheetBaseTheme.material:
|
case MarkdownStyleSheetBaseTheme.material:
|
||||||
default:
|
default:
|
||||||
return MarkdownStyleSheet.fromTheme(Theme.of(context));
|
result = MarkdownStyleSheet.fromTheme(Theme.of(context));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return result.copyWith(
|
||||||
|
textScaleFactor: MediaQuery.textScaleFactorOf(context),
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
Widget _handleDataSchemeUri(Uri uri, final double width, final double height) {
|
Widget _handleDataSchemeUri(Uri uri, final double width, final double height) {
|
||||||
|
@ -43,18 +43,26 @@ final MarkdownStyleSheet Function(BuildContext, MarkdownStyleSheetBaseTheme)
|
|||||||
BuildContext context,
|
BuildContext context,
|
||||||
MarkdownStyleSheetBaseTheme baseTheme,
|
MarkdownStyleSheetBaseTheme baseTheme,
|
||||||
) {
|
) {
|
||||||
|
MarkdownStyleSheet result;
|
||||||
switch (baseTheme) {
|
switch (baseTheme) {
|
||||||
case MarkdownStyleSheetBaseTheme.platform:
|
case MarkdownStyleSheetBaseTheme.platform:
|
||||||
final String userAgent = window.navigator.userAgent;
|
final String userAgent = window.navigator.userAgent;
|
||||||
return userAgent.contains('Mac OS X')
|
result = userAgent.contains('Mac OS X')
|
||||||
? MarkdownStyleSheet.fromCupertinoTheme(CupertinoTheme.of(context))
|
? MarkdownStyleSheet.fromCupertinoTheme(CupertinoTheme.of(context))
|
||||||
: MarkdownStyleSheet.fromTheme(Theme.of(context));
|
: MarkdownStyleSheet.fromTheme(Theme.of(context));
|
||||||
|
break;
|
||||||
case MarkdownStyleSheetBaseTheme.cupertino:
|
case MarkdownStyleSheetBaseTheme.cupertino:
|
||||||
return MarkdownStyleSheet.fromCupertinoTheme(CupertinoTheme.of(context));
|
result =
|
||||||
|
MarkdownStyleSheet.fromCupertinoTheme(CupertinoTheme.of(context));
|
||||||
|
break;
|
||||||
case MarkdownStyleSheetBaseTheme.material:
|
case MarkdownStyleSheetBaseTheme.material:
|
||||||
default:
|
default:
|
||||||
return MarkdownStyleSheet.fromTheme(Theme.of(context));
|
result = MarkdownStyleSheet.fromTheme(Theme.of(context));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return result.copyWith(
|
||||||
|
textScaleFactor: MediaQuery.textScaleFactorOf(context),
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
Widget _handleDataSchemeUri(Uri uri, final double width, final double height) {
|
Widget _handleDataSchemeUri(Uri uri, final double width, final double height) {
|
||||||
|
@ -577,7 +577,7 @@ class MarkdownBuilder implements md.NodeVisitor {
|
|||||||
if (selectable) {
|
if (selectable) {
|
||||||
return SelectableText.rich(
|
return SelectableText.rich(
|
||||||
text,
|
text,
|
||||||
//textScaleFactor: styleSheet.textScaleFactor,
|
textScaleFactor: styleSheet.textScaleFactor,
|
||||||
textAlign: textAlign ?? TextAlign.start,
|
textAlign: textAlign ?? TextAlign.start,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
|
@ -50,7 +50,7 @@ class MarkdownStyleSheet {
|
|||||||
this.orderedListAlign = WrapAlignment.start,
|
this.orderedListAlign = WrapAlignment.start,
|
||||||
this.blockquoteAlign = WrapAlignment.start,
|
this.blockquoteAlign = WrapAlignment.start,
|
||||||
this.codeblockAlign = WrapAlignment.start,
|
this.codeblockAlign = WrapAlignment.start,
|
||||||
this.textScaleFactor = 1.0,
|
this.textScaleFactor,
|
||||||
}) : _styles = <String, TextStyle>{
|
}) : _styles = <String, TextStyle>{
|
||||||
'a': a,
|
'a': a,
|
||||||
'p': p,
|
'p': p,
|
||||||
@ -130,6 +130,7 @@ class MarkdownStyleSheet {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
// textScaleFactor:
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -394,26 +395,26 @@ class MarkdownStyleSheet {
|
|||||||
MarkdownStyleSheet merge(MarkdownStyleSheet other) {
|
MarkdownStyleSheet merge(MarkdownStyleSheet other) {
|
||||||
if (other == null) return this;
|
if (other == null) return this;
|
||||||
return copyWith(
|
return copyWith(
|
||||||
a: other.a,
|
a: a.merge(other.a),
|
||||||
p: other.p,
|
p: p.merge(other.p),
|
||||||
code: other.code,
|
code: code.merge(other.code),
|
||||||
h1: other.h1,
|
h1: h1.merge(other.h1),
|
||||||
h2: other.h2,
|
h2: h2.merge(other.h2),
|
||||||
h3: other.h3,
|
h3: h3.merge(other.h3),
|
||||||
h4: other.h4,
|
h4: h4.merge(other.h4),
|
||||||
h5: other.h5,
|
h5: h5.merge(other.h5),
|
||||||
h6: other.h6,
|
h6: h6.merge(other.h6),
|
||||||
em: other.em,
|
em: em.merge(other.em),
|
||||||
strong: other.strong,
|
strong: strong.merge(other.strong),
|
||||||
del: other.del,
|
del: del.merge(other.del),
|
||||||
blockquote: other.blockquote,
|
blockquote: blockquote.merge(other.blockquote),
|
||||||
img: other.img,
|
img: img.merge(other.img),
|
||||||
checkbox: other.checkbox,
|
checkbox: checkbox.merge(other.checkbox),
|
||||||
blockSpacing: other.blockSpacing,
|
blockSpacing: other.blockSpacing,
|
||||||
listIndent: other.listIndent,
|
listIndent: other.listIndent,
|
||||||
listBullet: other.listBullet,
|
listBullet: listBullet.merge(other.listBullet),
|
||||||
tableHead: other.tableHead,
|
tableHead: tableHead.merge(other.tableHead),
|
||||||
tableBody: other.tableBody,
|
tableBody: tableBody.merge(other.tableBody),
|
||||||
tableHeadAlign: other.tableHeadAlign,
|
tableHeadAlign: other.tableHeadAlign,
|
||||||
tableBorder: other.tableBorder,
|
tableBorder: other.tableBorder,
|
||||||
tableColumnWidth: other.tableColumnWidth,
|
tableColumnWidth: other.tableColumnWidth,
|
||||||
|
@ -779,6 +779,39 @@ void main() {
|
|||||||
final RichText richText = tester.widget(find.byType(RichText));
|
final RichText richText = tester.widget(find.byType(RichText));
|
||||||
expect(richText.textScaleFactor, 2.0);
|
expect(richText.textScaleFactor, 2.0);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
testWidgets(' - should use MediaQuery textScaleFactor in RichText',
|
||||||
|
(WidgetTester tester) async {
|
||||||
|
await tester.pumpWidget(_boilerplate(
|
||||||
|
MediaQuery(
|
||||||
|
data: MediaQueryData(textScaleFactor: 2.0),
|
||||||
|
child: MarkdownBody(
|
||||||
|
data: 'Hello',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
));
|
||||||
|
|
||||||
|
final RichText richText = tester.widget(find.byType(RichText));
|
||||||
|
expect(richText.textScaleFactor, 2.0);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets(
|
||||||
|
' - should use MediaQuery textScaleFactor in SelectableText.rich',
|
||||||
|
(WidgetTester tester) async {
|
||||||
|
await tester.pumpWidget(_boilerplate(
|
||||||
|
MediaQuery(
|
||||||
|
data: MediaQueryData(textScaleFactor: 2.0),
|
||||||
|
child: MarkdownBody(
|
||||||
|
data: 'Hello',
|
||||||
|
selectable: true,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
));
|
||||||
|
|
||||||
|
final SelectableText selectableText =
|
||||||
|
tester.widget(find.byType(SelectableText));
|
||||||
|
expect(selectableText.textScaleFactor, 2.0);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
group('Custom builders', () {
|
group('Custom builders', () {
|
||||||
@ -995,11 +1028,15 @@ void main() {
|
|||||||
testWidgets('merge', (WidgetTester tester) async {
|
testWidgets('merge', (WidgetTester tester) async {
|
||||||
final ThemeData theme = ThemeData.light().copyWith(textTheme: textTheme);
|
final ThemeData theme = ThemeData.light().copyWith(textTheme: textTheme);
|
||||||
final MarkdownStyleSheet style1 = MarkdownStyleSheet.fromTheme(theme);
|
final MarkdownStyleSheet style1 = MarkdownStyleSheet.fromTheme(theme);
|
||||||
final MarkdownStyleSheet style2 =
|
final MarkdownStyleSheet style2 = MarkdownStyleSheet(
|
||||||
MarkdownStyleSheet(p: TextStyle(color: Colors.red));
|
p: TextStyle(color: Colors.red),
|
||||||
|
blockquote: TextStyle(fontSize: 16),
|
||||||
|
);
|
||||||
|
|
||||||
final MarkdownStyleSheet merged = style1.merge(style2);
|
final MarkdownStyleSheet merged = style1.merge(style2);
|
||||||
expect(merged.p.color, Colors.red);
|
expect(merged.p.color, Colors.red);
|
||||||
|
expect(merged.blockquote.fontSize, 16);
|
||||||
|
expect(merged.blockquote.color, theme.textTheme.bodyText2.color);
|
||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('create based on which theme', (WidgetTester tester) async {
|
testWidgets('create based on which theme', (WidgetTester tester) async {
|
||||||
|
Reference in New Issue
Block a user