DartCodeViewerThemeData class

Holds the color, size, and text styles for a dart code viewer theme.

Use this class to configure a DartCodeViewerThemeData widget.

To obtain the current ambient dart code viewer theme, use DartCodeViewerTheme.of.

The parts of the dart code viewer are:

  • The 'data, which is the String that is supposed to be transformed into dart highlighted code.
  • The 'highlightedTextStyle' which the different type of highlighted code that can be highlighted differently.

The simplest way to create a DartCodeThemeData is to use the copyWith on the one you get from DartCodeViewerTheme.of, or create an entirely new one with DartCodeViewerThemeData.

{@tool dartpad --template=stateless_widget_scaffold}

Here is an example of a small string that shows up as Dart code in a flutter application. With DartCodeViewerThemeData applied

@override
Widget build(BuildContext context) {
  return DartCodeViewerTheme(
    data: DartCodeViewerThemeData(
      backgroundColor: Colors.pink,
      child: DartCodeViewer(r'class DartCodeViewer extends StatelessWidget {}'),
    );
  );
}

{@end-tool}

See also:

  • DartCodeViewerThemeData, which describes the actual configuration of a DartCodeViewerTheme
  • Code viewer online tool is a useful tool that lets you choose the color for each different style. On the left side you put your example code and on the right you can choose the colors you want the code viewer to display. background => backgroundColor plain text => baseStyle Punctuation => punctuationStyle String, values => stringStyle Keywords, tags => keywordStyle Comments => commentStyle Types => classStyle Numbers => numberStyle Declarations => constantStyle
Mixed in types
Annotations

Constructors

DartCodeViewerThemeData({TextStyle? baseStyle, TextStyle? classStyle, TextStyle? commentStyle, TextStyle? constantStyle, TextStyle? keywordStyle, TextStyle? numberStyle, TextStyle? punctuationStyle, TextStyle? stringStyle, Color? backgroundColor, Text? copyButtonText, bool? showCopyButton, double? height, double? width, ButtonStyle? buttonStyle})
const

Properties

backgroundColor Color?
The background Color of the code. By default it is Theme.of(context).colorScheme.background.
final
baseStyle TextStyle?
The text style for the plain text in code.
final
buttonStyle ButtonStyle?
The buttonThemeData for the DartCodeViewer. Useful if you want the copy button to appear differently than the default.
final
classStyle TextStyle?
The text style for the code types in the code.
final
commentStyle TextStyle?
The text style for the commented out code.
final
constantStyle TextStyle?
The text style for the constant style code.
final
copyButtonText Text?
The text shown in the copy button by default it is 'COPY ALL'.
final
hashCode int
The hash code for this object.
no setteroverride
height double?
The height of the DartCodeViewer by default it uses the MediaQuery.of(context).size.height
final
keywordStyle TextStyle?
The text style for keywords. For example:
final
numberStyle TextStyle?
The text style for numbers within the code.
final
punctuationStyle TextStyle?
The text style for punctuation code like periods and commas.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
showCopyButton bool?
Shows copy button that lets user copy all the code as a raw string. By default the button is showing.
final
stringStyle TextStyle?
The text style for Strings. For example the data when using the Text widget.
final
width double?
The width of the DartCodeViewer by default it uses the MediaQuery.of(context).size.width
final

Methods

copyWith({TextStyle? baseStyle, TextStyle? classStyle, TextStyle? commentStyle, TextStyle? constantStyle, TextStyle? keywordStyle, TextStyle? numberStyle, TextStyle? punctuationStyle, TextStyle? stringStyle, Color? backgroundColor, Text? copyButtonText, bool? showCopyButton, double? height, double? width, ButtonStyle? buttonStyle}) DartCodeViewerThemeData
Creates a copy of this object but with the given fields replaced with the new values.
debugFillProperties(DiagnosticPropertiesBuilder properties) → void
Add additional properties associated with the node.
override
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
toStringShort() String
A brief description of this object, usually just the runtimeType and the hashCode.
inherited

Operators

operator ==(Object other) bool
The equality operator.
override

Static Methods

lerp(DartCodeViewerThemeData a, DartCodeViewerThemeData b, double t) DartCodeViewerThemeData
Linearly interpolate between two dart code viewer themes.