一個 Dart 包裝器,用於 CodeMirror 文本編輯器,讓 Flutter Web 應用程式能夠實現豐富的程式碼編輯功能。它提供語法強調、行號顯示和可自訂主題,直接在瀏覽器中利用強大的 CodeMirror 庫。此套件非常適合建立互動式程式碼編輯器、類似 IDE 的功能,或任何需要支援特定語言語法的進階文字編輯應用程式。對於僅限 Web 的 Flutter 項目,整合無縫,確保熟悉且高效能的編輯體驗。
適用情境
基於網路的程式碼編輯器
互動式編碼教程
類似IDE的Web應用
即時程式碼協作
語法高亮輸入欄位
主要特色
語法強調
行號
可自訂主題
基於瀏覽器的渲染
透過 CodeMirror 外掛程式可擴充
適合對象
Flutter web 開發人員
教育平台
程式碼分享工具
開發者工具
基於網路的整合開發環境
使用建議
僅限 Web 的平台支援
需要 JavaScript 互操作
僅限瀏覽器環境
依賴外部 CodeMirror 庫
可能增加封包大小
原始 README
以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。
codemirror.dart
What is it?
A Dart wrapper around the CodeMirror text editor. From
codemirror.net:
CodeMirror is a versatile text editor implemented in JavaScript for the
browser. It is specialized for editing code, and comes with a number of language
modes and addons that implement more advanced editing functionality.
Note: This is NOT a Flutter package, it is a Dart package for writing web applications
like DartPad.
An example
final options = <String, String>{
'mode': 'javascript',
'theme': 'monokai'
};
final editor = CodeMirror.fromElement(
document.querySelector('#textContainer')!, options: options);
editor.doc.setValue('foo.bar(1, 2, 3);');
This Dart package ships with several language modes built in. CodeMirror itself
supports over 100 modes; the modes built into the Dart package include the
usual suspects for web development - css, html, dart and javascript as
well as a few
others.
In order to add additional modes, you'll need to reference the mode file from
your html entry point. So,
Similarly with addons, we've included a few common ones, and have made the
others available to import on a case-by-case basis. In order to use the
active-line addon, import:
Be aware that many addons need additional configuration in order to enable then.
This is generally done by passing values into the options of the CodeMirror
constructor.
Some addons are exposed through the main Dart interface. Some are exposed via
side-car Dart libraries available in the main
package, and some
have yet to be exposed. Pull requests welcome :)
You get access to all the CodeMirror themes. If you only want a few, or don't
want to pay the network roundtrip cost to load all the themes, you can import
only the ones you're interested in: