syntax_highlight
0.5.0, released a year ago by serverpod.dev
VSCode-style syntax highlighting and code editing widgets for Flutter.
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.
- code_editor
A Flutter code editor widget with syntax highlighting, custom themes, and file navigation.
82Compare - re_highlight
Powerful text syntax highlighting library translated from highlightjs.
50Compare - flutter_code_editor
A customizable code field widget supporting syntax highlighting and code folding.
65Compare - shiki_flutter
TextMate-grammar based syntax highlighter for Flutter ported from Shiki.
59Compare
Works with
Packages commonly used together with syntax_highlight: ones it builds on, ones built on it, and its own family.
- string_scannersyntax_highlight depends on itA class for parsing strings using a sequence of patterns.
- super_clipboardsyntax_highlight depends on itComprehensive clipboard access package supporting rich text, images, and custom data formats.
- flutter_tailwind_uiBuilt on syntax_highlightTailwind‑style UI widgets and theming for Flutter apps
- flutter_deckBuilt on syntax_highlightA lightweight, customizable framework to create presentations in Flutter.