of static method

Returns the data from the closest DartCodeViewerTheme instances the encloses the given context.

The default parameters is set within the DartCodeViewer.

{@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

Implementation

static DartCodeViewerThemeData of(BuildContext context) {
  final dartCodeViewerTheme = context.dependOnInheritedWidgetOfExactType<DartCodeViewerTheme>();
  return dartCodeViewerTheme?.data ?? const DartCodeViewerThemeData();
}