Skip to content
pubscout

dart_code_viewer2

1.0.3, released 2 years ago by bangkit.dev

A Flutter widget to view, theme, and copy Dart code snippets.

WASM-ready
$ flutter pub add dart_code_viewer2
Source repository

What it does

The dart_code_viewer2 package lets you easily display and copy formatted Dart code inside your Flutter application. It supports built-in themes, custom text styles, and color parameters for highlighting tokens like keywords, strings, comments, and types.

AI-written summary of version 1.0.3, based on the package's README and metadata. Report an inaccuracy

Use it when

  • You need to display code examples inside a Flutter application
  • You want built-in support for copying code snippets to the clipboard
  • You need syntax highlighting and theme customization for code display

Skip it when

  • You need a full-featured code editor rather than just a viewer
  • You need support for highlighting languages other than Dart

Strengths

  • Easy to set up with pre-made themes like light, dark, io17, and designDark
  • Supports custom text styling and color parameters per token type
  • Includes a copy button feature out of the box

Weaknesses

  • Limited to displaying Dart code
  • Requires a Material ancestor and MediaQuery widget in the tree

Setup

Kind
Flutter widgets
Effort
Low
Code generation
No
Direct dependencies
1

No native setup required. Just add the dependency to pubspec.yaml.

DartCodeViewer(r'''
void main() {
  runApp(MyApp());
}
''',
)

Alternatives

Packages that do the same job and could replace dart_code_viewer2.

Works with

Packages commonly used together with dart_code_viewer2: ones it builds on, ones built on it, and its own family.