ShikiCodeView class
Displays code highlighted with the given lang and theme.
lang is a CodeLanguage and theme is a single ShikiTheme or a
ShikiDualTheme light/dark pair; the widget loads them into the
highlighter on demand, so no pre-loading is required. When theme is
omitted it falls back to the global ShikiHighlighter.config.defaultTheme,
throwing a ShikiError if that is also unset. A dual pair is resolved from
the ambient Theme.of(context) brightness (override it with brightness).
The widget paints the resolved theme's background color behind the code and
applies its foreground as the default text color.
When async highlighting is active (see ShikiHighlighter.config.async), the code
first appears as plain text in the theme's base color while it is tokenized
on a background isolate, then swaps to the highlighted result, which is
cached, so later rebuilds are instant.
Set selectable to true to let users select and copy the code; it wraps
the subtree in a SelectionArea, unless an ancestor already provides one.
Set showLineNumbers to true for a line-number gutter (styled via
gutterStyle). The code stays a single Text.rich; a fixed numbers column
is placed beside it and never scrolls horizontally.
- Inheritance
-
- Object
- DiagnosticableTree
- Widget
- StatefulWidget
- ShikiCodeView
Constructors
- ShikiCodeView({Key? key, ShikiHighlighter? highlighter, required String code, required CodeLanguage lang, ShikiThemeBase? theme, Brightness? brightness, TextStyle? textStyle, EdgeInsetsGeometry padding = const EdgeInsets.all(16), bool paintBackground = true, bool selectable = false, TextScaler? textScaler, bool showLineNumbers = false, GutterStyle gutterStyle = const GutterStyle(), bool? async})
-
Creates a highlighted code view rendered as a single
Text.rich.codeandlangare required; see the class docs for howtheme/brightnessand the async placeholder behavior work.const
Properties
- async → bool?
-
Overrides the global
ShikiHighlighter.config.asyncdefault for this widget. When null, the global default applies.finalinherited - brightness → Brightness?
-
Overrides the brightness used to pick a ShikiDualTheme theme. When
null, the ambient
Theme.of(context).brightnessis used.finalinherited - code → String
-
The code to highlight. It is tokenized on demand, then cached for later rebuilds.
finalinherited
- gutterStyle → GutterStyle
-
Styling for the line-number gutter: the numbers' color and scale, the gap
between the gutter and the code, and an optional divider. Only used when
showLineNumbersistrue.finalinherited - hashCode → int
-
The hash code for this object.
no setterinherited
- highlighter → ShikiHighlighter?
-
The highlighter to render with. Optional: when null, the widget uses the
shared default (
ShikiHighlighter.config.defaultHighlighter, or a lazily-created instance). The language and resolved theme are loaded into it on demand, so no pre-loading is required.finalinherited - key → Key?
-
Controls how one widget replaces another widget in the tree.
finalinherited
- lang → CodeLanguage
-
The language to highlight
codeas. Loaded intohighlighteron demand.finalinherited - padding → EdgeInsetsGeometry
-
Padding around the code.
finalinherited
- paintBackground → bool
-
Whether to paint the theme's background color behind the code.
finalinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- selectable → bool
-
Whether to make the code selectable by wrapping the subtree in a
SelectionArea. Defaults to
false.finalinherited - selectionColor → Color?
-
Highlight color for selected code. Defaults to the ambient selection color
(e.g. the app theme's TextSelectionThemeData.selectionColor).
finalinherited
- showLineNumbers → bool
-
Show a line-number gutter to the left of the code.
finalinherited
- textScaler → TextScaler?
-
Optional text scaling factor for the code. When null, the ambient
text scaling factor is used.
finalinherited
- textStyle → TextStyle?
-
Base text style. A monospace
fontFamilyis recommended.finalinherited - theme → ShikiThemeBase?
-
The theme(s) to render with: a single theme or a light/dark pair. When
null, falls back to the global
ShikiHighlighter.config.defaultTheme; if both are null a ShikiError is thrown.finalinherited
Methods
-
createElement(
) → StatefulElement -
Creates a StatefulElement to manage this widget's location in the tree.
inherited
-
createState(
) → State< ShikiCodeView> -
Creates the mutable state for this widget at a given location in the tree.
override
-
debugDescribeChildren(
) → List< DiagnosticsNode> -
Returns a list of DiagnosticsNode objects describing this node's
children.
inherited
-
debugFillProperties(
DiagnosticPropertiesBuilder properties) → void -
Add additional properties associated with the node.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toDiagnosticsNode(
{String? name, DiagnosticsTreeStyle? style}) → DiagnosticsNode -
Returns a debug representation of the object that is used by debugging
tools and by DiagnosticsNode.toStringDeep.
inherited
-
toString(
{DiagnosticLevel minLevel = DiagnosticLevel.info}) → String -
A string representation of this object.
inherited
-
toStringDeep(
{String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug, int wrapWidth = 65}) → String -
Returns a string representation of this node and its descendants.
inherited
-
toStringShallow(
{String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) → String -
Returns a one-line detailed description of the object.
inherited
-
toStringShort(
) → String -
A short, textual description of this widget.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited