Skip to content
pubscout

syntax_highlight

0.5.0, released a year ago by serverpod.dev

VSCode-style syntax highlighting and code editing widgets for Flutter.

WASM-ready
$ flutter pub add syntax_highlight
Source repository

What it does

The package uses TextMate rules to provide syntax highlighting for multiple programming languages, returning a formatted TextSpan. It also includes a simplistic CodeEditor widget supporting rich text copying.

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

Use it when

  • You need to display syntax-highlighted code blocks in your Flutter application.
  • You require a basic code editor widget with rich text copy capabilities.

Skip it when

  • You need advanced code editing features like line numbers, complex autocompletion, or deep IDE integrations.

Strengths

  • Supports many popular programming languages out of the box using TextMate grammar rules.
  • Provides a ready-to-use CodeEditor widget.
  • Easy to extend with new grammar files.

Weaknesses

  • Requires manual asynchronous initialization of languages and themes before use.
  • The bundled CodeEditor is simplistic.

Setup

Kind
Flutter widgets
Effort
Low
Code generation
No
Direct dependencies
3

Requires initializing the highlighter and loading themes and grammar files asynchronously before use.

await Highlighter.initialize(['dart', 'yaml']);
var theme = await HighlighterTheme.loadLightTheme();
var highlighter = Highlighter(language: 'dart', theme: theme);
Widget build(BuildContext context) {
  var highlightedCode = highlighter.highlight(myCodeString);
  return Text.rich(highlightedCode);
}

Alternatives

Packages that do the same job and could replace syntax_highlight.

Works with

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