MarkdownStyleSheet class
Defines the visual styling for all Markdown elements.
MarkdownStyleSheet provides comprehensive control over the appearance of rendered markdown content. It includes text styles for different elements (headers, paragraphs, code, links, etc.) as well as decorations for containers (blockquotes, code blocks, tables).
Usage
Most commonly, you'll use one of the built-in factory constructors rather than creating a custom stylesheet from scratch:
// Use the default light theme
SmoothMarkdown(
data: markdownText,
styleSheet: MarkdownStyleSheet.light(),
)
// Use GitHub-style theme
SmoothMarkdown(
data: markdownText,
styleSheet: MarkdownStyleSheet.github(),
)
// Adapt to app's theme automatically
SmoothMarkdown(
data: markdownText,
styleSheet: MarkdownStyleSheet.fromTheme(Theme.of(context)),
)
Customization
To customize a theme, use copyWith to override specific properties:
final customSheet = MarkdownStyleSheet.light().copyWith(
h1Style: TextStyle(
fontSize: 36,
fontWeight: FontWeight.w900,
color: Colors.purple,
),
linkStyle: TextStyle(
color: Colors.blue[700],
decoration: TextDecoration.none, // Remove underline
),
codeBlockDecoration: BoxDecoration(
color: Colors.grey[900],
borderRadius: BorderRadius.circular(12),
),
);
Available Themes
- light(): Clean, readable light theme (default)
- dark(): Dark theme for dark mode apps
- github(): Mimics GitHub's markdown styling (light or dark)
- vscode(): VS Code editor-style theme (light or dark)
- fromTheme(): Adapts to Flutter's ThemeData automatically
- fromBrightness(): Creates theme based on brightness setting
Styling Categories
The stylesheet includes properties for:
Text Styles:
- Headers (h1-h6), paragraphs, blockquotes
- Inline formatting (bold, italic, strikethrough, code)
- Links, list bullets, table cells
Container Decorations:
- Blockquotes, code blocks, tables
- Table headers and alternating row colors
- Horizontal rules
Spacing & Layout:
- Block spacing, list indentation
- Padding for blockquotes, code blocks, table cells
See also:
- SmoothMarkdown, which uses this stylesheet for rendering
- MarkdownConfig, for configuring parsing behavior
Constructors
- MarkdownStyleSheet({TextStyle? textStyle, TextStyle? h1Style, TextStyle? h2Style, TextStyle? h3Style, TextStyle? h4Style, TextStyle? h5Style, TextStyle? h6Style, TextStyle? paragraphStyle, TextStyle? blockquoteStyle, TextStyle? codeBlockStyle, TextStyle? inlineCodeStyle, TextStyle? linkStyle, TextStyle? boldStyle, TextStyle? italicStyle, TextStyle? strikethroughStyle, TextStyle? listBulletStyle, TextStyle? tableHeaderStyle, TextStyle? tableCellStyle, BoxDecoration? blockquoteDecoration, BoxDecoration? codeBlockDecoration, TableBorder? tableBorder, BoxDecoration? tableHeaderDecoration, BoxDecoration? tableOddRowDecoration, BoxDecoration? tableEvenRowDecoration, Color? horizontalRuleColor, double? horizontalRuleThickness, double? blockSpacing, double? listIndent, EdgeInsets? blockquotePadding, EdgeInsets? codeBlockPadding, EdgeInsets? tableCellPadding})
-
Creates a custom Markdown style sheet.
const
- MarkdownStyleSheet.dark({TextStyle? baseStyle})
-
Creates a comfortable dark theme style sheet for dark mode apps.
factory
- MarkdownStyleSheet.fromBrightness(Brightness brightness, {TextStyle? baseStyle})
-
Creates a style sheet based on brightness value.
factory
- MarkdownStyleSheet.fromTheme(ThemeData theme)
-
Creates a style sheet that adapts to Flutter's ThemeData.
factory
- MarkdownStyleSheet.github({Brightness brightness = Brightness.light})
-
Creates a GitHub-style theme that mimics GitHub's markdown rendering.
factory
- MarkdownStyleSheet.light({TextStyle? baseStyle})
-
Creates a clean, readable light theme style sheet.
factory
- MarkdownStyleSheet.vscode({Brightness brightness = Brightness.light})
-
Creates a VS Code-style theme that mimics the VS Code editor.
factory
Properties
- blockquoteDecoration → BoxDecoration?
-
Decoration for blockquotes
final
- blockquotePadding → EdgeInsets?
-
Padding for blockquotes
final
- blockquoteStyle → TextStyle?
-
Blockquote text style
final
- blockSpacing → double?
-
Spacing between block elements
final
- boldStyle → TextStyle?
-
Bold text style
final
- codeBlockDecoration → BoxDecoration?
-
Decoration for code blocks
final
- codeBlockPadding → EdgeInsets?
-
Padding for code blocks
final
- codeBlockStyle → TextStyle?
-
Code block text style
final
- h1Style → TextStyle?
-
H1 heading style
final
- h2Style → TextStyle?
-
H2 heading style
final
- h3Style → TextStyle?
-
H3 heading style
final
- h4Style → TextStyle?
-
H4 heading style
final
- h5Style → TextStyle?
-
H5 heading style
final
- h6Style → TextStyle?
-
H6 heading style
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- horizontalRuleColor → Color?
-
Color for horizontal rules
final
- horizontalRuleThickness → double?
-
Thickness of horizontal rules
final
- inlineCodeStyle → TextStyle?
-
Inline code style
final
- italicStyle → TextStyle?
-
Italic text style
final
- linkStyle → TextStyle?
-
Link style
final
- listBulletStyle → TextStyle?
-
List bullet style
final
- listIndent → double?
-
Indentation for lists
final
- paragraphStyle → TextStyle?
-
Paragraph style
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- strikethroughStyle → TextStyle?
-
Strikethrough text style
final
- tableBorder → TableBorder?
-
Border for tables
final
- tableCellPadding → EdgeInsets?
-
Padding for table cells
final
- tableCellStyle → TextStyle?
-
Table cell style
final
- tableEvenRowDecoration → BoxDecoration?
-
Decoration for even table rows
final
- tableHeaderDecoration → BoxDecoration?
-
Decoration for table header row
final
- tableHeaderStyle → TextStyle?
-
Table header style
final
- tableOddRowDecoration → BoxDecoration?
-
Decoration for odd table rows
final
- textStyle → TextStyle?
-
Default text style
final
Methods
-
copyWith(
{TextStyle? textStyle, TextStyle? h1Style, TextStyle? h2Style, TextStyle? h3Style, TextStyle? h4Style, TextStyle? h5Style, TextStyle? h6Style, TextStyle? paragraphStyle, TextStyle? blockquoteStyle, TextStyle? codeBlockStyle, TextStyle? inlineCodeStyle, TextStyle? linkStyle, TextStyle? boldStyle, TextStyle? italicStyle, TextStyle? strikethroughStyle, TextStyle? listBulletStyle, TextStyle? tableHeaderStyle, TextStyle? tableCellStyle, BoxDecoration? blockquoteDecoration, BoxDecoration? codeBlockDecoration, TableBorder? tableBorder, BoxDecoration? tableHeaderDecoration, BoxDecoration? tableOddRowDecoration, BoxDecoration? tableEvenRowDecoration, Color? horizontalRuleColor, double? horizontalRuleThickness, double? blockSpacing, double? listIndent, EdgeInsets? blockquotePadding, EdgeInsets? codeBlockPadding, EdgeInsets? tableCellPadding}) → MarkdownStyleSheet - Creates a copy of this style sheet with the given fields replaced
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited