Search packages, repositories and app categories

syntax_highlight cover
Package detailsv0.5.0

syntax_highlight

Syntax highlighting in the style of VSCode for Flutter, takes a string and returns a formatted TextSpan.

AndroidiOSWebmacOSWindowsLinux
30-day downloads
27.3K
Likes
79
Pub points
150

Install package

flutter pub add syntax_highlight

Package Overview

Package selection guidance compiled from public package information, community data, and project usage.

A Flutter/Dart package that provides VSCode-style syntax highlighting for code snippets. It takes a plain text string and converts it into a formatted TextSpan with appropriate colors for keywords, strings, comments, and other language elements. Ideal for displaying code in apps, documentation, or development tools. The package supports multiple platforms including Android, iOS, Web, macOS, Windows, and Linux, ensuring consistent rendering across devices. It is lightweight and integrates seamlessly into existing Flutter projects.

Use cases

  • Displaying code snippets in documentation apps
  • Enhancing code editor widgets in IDE-like applications
  • Highlighting source code in learning or tutorial platforms
  • Integrating syntax-aware text rendering in developer tools
  • Visualizing code in real-time collaboration apps

Key features

  • VSCode-inspired color schemes
  • Supports multiple programming languages
  • Returns a TextSpan for easy integration
  • Lightweight and performant
  • Cross-platform compatibility
  • Configurable themes and styles

Suitable for

  • Flutter developers building code editors
  • Educational apps with code examples
  • Developer tooling and IDE extensions
  • Documentation and tutorial platforms
  • Real-time code sharing or collaboration apps

Considerations

  • Requires manual language detection or specification
  • Limited to basic syntax rules (no advanced parsing)
  • May need customization for non-standard languages
  • Performance depends on input size
  • Does not support dynamic language switching at runtime

Original README

Original README snapshot from the linked source repository. Visit the repository for the latest content.

Flutter Syntax Highlight

Syntax Highlight

The Syntax Highlight package uses the TextMate rules for highlighting code, which is used by many popular applications such as VSCode. It is easy to extend the language support by dropping in new grammar files in the grammars directory.

Currently supported languages are: css, dart, go, html, java, javascript, json, kotlin, python, rust, serverpod_protocol, sql, swift, typescript, and yaml.

Code editor

The Syntax Highlight package also comes bundled with a CodeEditor widget, which provides a simplistic interface for editing code. It supports rich text copy (e.g., for pasting into Google Slides).

Live Demo

Usage

Before you can use the Highlighter class it needs to be initialized. The initialization will load the requested grammar files and parse them.

// Initialize the highlighter.
await Highlighter.initialize(['dart', 'yaml', 'sql']);

Next load a theme and create a highlighter.

// Load the default light theme and create a highlighter.
var theme = await HighlighterTheme.loadLightTheme();
var highlighter = Highlighter(
  language: 'dart',
  theme: theme,
);

Now, you can highlight your code by calling the highlight method. The highlight method will return a TextSpan, which you can use in a Text widget.

Widget build(BuildContext context) {
  var highlightedCode = highlighter.highlight(myCodeString);
  return Text.rich(highlightedCode);
}

An example of highlighted code: Highlighted code

Categories

Dependencies

Dependency list 3 items

Source repository

Projects using this package