搜索插件、代码仓与 APP 分类

插件详情v0.7.14+5.65.18

codemirror

一个围绕 CodeMirror 文本编辑器的 Dart 包装器。

Web
近 30 天下载
1330
喜欢数
20
Pub 分数
120

安装插件

flutter pub add codemirror

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

一个 Dart 包装器,用于 CodeMirror 文本编辑器,使 Flutter Web 应用程序能够实现丰富的代码编辑功能。它提供语法高亮、行号显示和可自定义的主题,直接在浏览器中利用强大的 CodeMirror 库。该包非常适合构建交互式代码编辑器、类似 IDE 的功能,或任何需要支持特定编程语言语法的高级文本编辑的应用程序。对于仅限 Web 的 Flutter 项目,集成无缝,确保熟悉的高性能编辑体验。

适合场景

  • 基于网络的代码编辑器
  • 交互式编码教程
  • 类似IDE的Web应用
  • 实时代码协作
  • 语法高亮输入字段

主要特点

  • 语法高亮
  • 行号
  • 可自定义的主题
  • 基于浏览器的渲染
  • 通过 CodeMirror 插件可扩展

适合对象

  • Flutter web 开发人员
  • 教育平台
  • 代码共享工具
  • 开发者工具
  • 基于网络的集成开发环境

使用建议

  • 仅限 Web 的平台支持
  • 需要 JavaScript 互操作
  • 仅限浏览器环境
  • 依赖外部 CodeMirror 库
  • 可能增加打包大小

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

codemirror.dart

Build Status pub package

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);');

See also our example/ directory.

How do I use it?

In your main html file, link to the style sheet:

<link href="packages/codemirror/codemirror.css" rel="stylesheet">

reference the CodeMirror JavaScript code:

<script src="packages/codemirror/codemirror.js"></script>

and, in your Dart code, import the library:

import 'package:codemirror/codemirror.dart';

What about modes? Addons?

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,

<script src="packages/codemirror/mode/lua.js"></script>

will bring in support for Lua.

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:

<script src="packages/codemirror/addon/selection/active-line.js"></script>

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 :)

Themes

By importing the codemirror.css file:

<link href="packages/codemirror/codemirror.css" rel="stylesheet">

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:

<link href="packages/codemirror/theme/monokai.css" rel="stylesheet">
<link href="packages/codemirror/theme/zenburn.css" rel="stylesheet">

Disclaimer

This is not an official Google product.

所属分类

依赖

依赖清单 1 项

源码仓库

使用此插件的项目

暂无相关数据。