From 0a9bc9cc2466f58420d4d2ff4476270e0bcbe940 Mon Sep 17 00:00:00 2001 From: Feodor Fitsner Date: Sun, 18 Dec 2022 15:36:07 -0800 Subject: [PATCH] Remove hard-coded colors in Markdown default code theme Fix #728 --- package/lib/src/controls/highlight_view.dart | 8 ++++---- package/lib/src/controls/markdown.dart | 7 ++++--- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/package/lib/src/controls/highlight_view.dart b/package/lib/src/controls/highlight_view.dart index 88557239a..3f7a59d9a 100644 --- a/package/lib/src/controls/highlight_view.dart +++ b/package/lib/src/controls/highlight_view.dart @@ -74,8 +74,6 @@ class HighlightView extends StatelessWidget { } static const _rootKey = 'root'; - static const _defaultFontColor = Color(0xff000000); - static const _defaultBackgroundColor = Color(0xffffffff); // TODO: dart:io is not available at web platform currently // See: https://github.com/flutter/flutter/issues/39998 @@ -86,14 +84,16 @@ class HighlightView extends StatelessWidget { Widget build(BuildContext context) { var style = TextStyle( fontFamily: _defaultFontFamily, - color: theme[_rootKey]?.color ?? _defaultFontColor, + color: theme[_rootKey]?.color ?? + Theme.of(context).colorScheme.onSurfaceVariant, ); if (textStyle != null) { style = style.merge(textStyle); } var d = BoxDecoration( - color: theme[_rootKey]?.backgroundColor ?? _defaultBackgroundColor); + color: theme[_rootKey]?.backgroundColor ?? + Theme.of(context).colorScheme.surfaceVariant); if (decoration != null) { d = d.copyWith(borderRadius: (decoration as BoxDecoration).borderRadius); diff --git a/package/lib/src/controls/markdown.dart b/package/lib/src/controls/markdown.dart index 1363be7a3..05b9bf87f 100644 --- a/package/lib/src/controls/markdown.dart +++ b/package/lib/src/controls/markdown.dart @@ -26,7 +26,7 @@ class MarkdownControl extends StatelessWidget { final ws = FletAppServices.of(context).ws; var value = control.attrString("value", "")!; - var codeTheme = control.attrString("codeTheme", "github")!; + var codeTheme = control.attrString("codeTheme", "")!; md.ExtensionSet extensionSet = md.ExtensionSet.none; switch (control.attrString("extensionSet", "")!.toLowerCase()) { case "commonmark": @@ -60,7 +60,8 @@ class MarkdownControl extends StatelessWidget { imageDirectory: getBaseUri(pageUri!).toString(), extensionSet: extensionSet, builders: { - 'code': CodeElementBuilder(codeTheme, mdStyleSheet), + 'code': + CodeElementBuilder(codeTheme.toLowerCase(), mdStyleSheet), }, styleSheet: mdStyleSheet, onTapLink: (String text, String? href, String title) { @@ -105,7 +106,7 @@ class CodeElementBuilder extends MarkdownElementBuilder { // Specify highlight theme // All available themes are listed in `themes` folder - theme: themeMap[codeTheme] ?? themeMap["github"]!, + theme: themeMap[codeTheme] ?? {}, // Specify padding padding: mdStyleSheet.codeblockPadding,