搜尋套件、儲存庫與 APP 分類

套件詳情v0.1.2

val_highlight_flutter

用於語法強調程式碼的 Flutter 小部件:CodeView 用於顯示,CodeField 用於編輯,支援 55 種語言、主題與順暢的大檔案處理。

AndroidiOSLinuxmacOSWebWindows
近 30 天下載
6.7萬
喜歡數
8
Pub 分數
160

安裝套件

flutter pub add val_highlight_flutter

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

ValHighlightFlutter 為 Flutter 應用提供語法高亮的程式碼顯示與編輯元件。CodeView 支援 55 種語言並可自訂主題,而 CodeField 則支援即時高亮的互動式程式碼編輯。針對效能優化,可在所有平台(包含 Web、行動裝置與桌面)順暢處理大型檔案。適合需要清晰易讀程式碼呈現的文件工具、整合開發環境或教育類應用。

適用情境

  • 程式碼文件檢視器
  • 互動式編碼教學
  • IDE 類代碼編輯器
  • 應用程式中的開發人員工具
  • 即時程式碼預覽

主要特色

  • 支援 55 種程式語言
  • 可自訂的顏色主題
  • 大檔案的平滑渲染
  • CodeView 用於顯示,CodeField 用於編輯
  • 跨平台相容性

適合對象

  • 教育類應用
  • 開發者工具
  • 文件平台
  • 程式碼共用應用
  • 內部開發者工具

使用建議

  • 需要仔細設定主題以確保可讀性
  • 效能可能會隨著極大檔案而有所不同
  • 有限的內建自動補完
  • 無內建語言檢測
  • 最好與預格式化的程式碼字串一起使用

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

val_highlight

Syntax highlighting for Dart and Flutter.

A pure-Dart engine with 55 languages, incremental updates and themes,
plus Flutter widgets to show and edit code.

val_highlight on pub.dev val_highlight_flutter on pub.dev BSD-3-Clause license


📦 Packages

Package Use it for
val_highlight The engine, in pure Dart: 55 languages plus a generic fallback, flat tokens, incremental updates, language detection, 8 themes, VS Code theme import and HTML output. Runs on the VM, in Flutter and on the web.
val_highlight_flutter Flutter widgets: CodeView to show code, CodeField to edit it, HighlightTextController, and CodeTheme for app-wide defaults.

A val_highlight_jaspr package is planned, built on the same engine.

// Flutter
CodeView(source, language: dartLanguage)

// Pure Dart
final html = const Highlighter().toHtml(source, language: dartLanguage);
Dart in CodeView with line numbers and highlighted lines
CodeView
Line numbers, highlighted lines, selection.
TSX in the midnight theme
Themes
Eight built in, or import a VS Code theme.
Markdown with bash, Python and JSON code fences
Languages inside languages
Markdown fences, HTML with CSS and JavaScript.
Python being edited in CodeField
CodeField
An editor that highlights as you type.

⚡ Performance

just bench compiles to native code, highlights a Dart file and renders it to HTML (best of 5 runs, on a MacBook):

Lines Highlight + HTML
600 1.5 ms
2,400 4.3 ms
9,600 13.9 ms

just bench-languages measures about 256 KB of realistic source per language on native code. It averages about 43 MB/s, from 30 MB/s (HTML) to 64 MB/s (Markdown). just bench-js runs the same test compiled to JavaScript, where it averages about 62 MB/s.

With incremental highlighting, one keystroke in the 9,600-line file takes about 0.4 ms. Frame timings for scrolling and typing in Flutter are in the val_highlight_flutter README (just bench-frames).

How it works
  • One pass, no copying. The scanner walks the source by offset, never copies it, and time grows in step with input size.
  • First-character dispatch. Each rule's pattern is analysed once to find the characters it can start with. The scanner skips positions where no rule can start, and tries only the rules that can. Rules anchored with ^ are tried only at line starts. States with a rule that can start almost anywhere fall back to one combined regular expression. Both paths give identical results, and fuzz tests check this.
  • Plain-Dart matchers. On native platforms, most patterns run as small Dart matchers instead of the regular expression engine, with identical results (checked by fuzz tests). Browsers compile regular expressions to machine code, so the web keeps using them.
  • Flat output. Tokens are two integer lists, not a tree of objects.

🛠️ Development

This repository is a pub workspace. The Flutter version is pinned in .fvmrc (3.44.2), and the justfile runs everything through FVM:

just setup            # install the pinned SDK and fetch dependencies
just check            # format check, analyze, all tests (VM and JS)
just devices          # list available devices
just example-flutter  # run the Flutter example; asks which device to use
just example-web      # run the Flutter example in Chrome
just example-dart     # run the pure-Dart example
just bench            # benchmark

Run just with no arguments to list every command.

Note: with Xcode 27, Flutter 3.44.2 (the pinned version) fails to build for iOS, and to build macOS apps in profile or release mode, such as the frame benchmark. Its architecture check rejects Xcode 27's lipo output. Flutter 3.47 builds both. Web, Android and macOS debug builds work with the pin.

Built by Val

val_highlight is part of Val, the live visual layer for AI agents.

💬 Community

Issues and pull requests are welcome. See CONTRIBUTING.md for setup, tests and what we look for in a pull request.

📄 License

BSD 3-Clause — see LICENSE.

所屬分類

依賴

依賴清單 2 項

原始碼儲存庫

使用此套件的專案

暫無相關資料。

所在榜單