一个 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: