CodeEditor class

Creates a code editor.

You can freely define the styles of the editor, such as text style, line number view, search view, scroll bar, etc.

Similar to TextField, editor uses CodeLineEditingController as the content controller. You can create a controller using the following code.

final controller = CodeLineEditingController.fromText('Hello World');

or

final controller = CodeLineEditingController.fromFile('/Users/megatronking/hello.py');

If wordWrap mode is turned off, the editor will support both horizontal and vertical scrolling, and you can use CodeScrollController to control the scrolling.

You can use CodeFindBuilder to create search widget and use CodeFindController to control the widget and search actions.

The editor has many built-in shortcut key actions. If you need to customize shortcut keys, you can use shortcutsActivatorsBuilder or shortcutOverrideActions. By default, the editor will use DefaultCodeShortcutsActivatorsBuilder.

Regarding code folding, you can write a custom code folding analyzer with chunkAnalyzer. By default, the editor will use DefaultCodeChunkAnalyzer. This works for some commonly used languages, but may not work for some languages (such as python).

Inheritance

Constructors

CodeEditor({Key? key, CodeLineEditingController? controller, CodeScrollController? scrollController, CodeFindController? findController, SelectionToolbarController? toolbarController, ValueChanged<CodeLineEditingValue>? onChanged, CodeEditorStyle? style, String? hint, EdgeInsetsGeometry? padding, EdgeInsetsGeometry? margin, CodeIndicatorBuilder? indicatorBuilder, CodeScrollbarBuilder? scrollbarBuilder, CodeFindBuilder? findBuilder, CodeShortcutsActivatorsBuilder? shortcutsActivatorsBuilder, Map<Type, Action<Intent>>? shortcutOverrideActions, Widget? sperator, Border? border, bool? readOnly, bool? showCursorWhenReadOnly, bool? wordWrap, bool? autofocus, FocusNode? focusNode, CodeChunkAnalyzer? chunkAnalyzer, CodeCommentFormatter? commentFormatter})
const

Properties

autofocus bool?
Whether this editor field should focus itself if nothing else is already focused.
final
border Border?
The border of the editor.
final
chunkAnalyzer CodeChunkAnalyzer?
Decide which parts of code can be folded.
final
commentFormatter CodeCommentFormatter?
Control how one or more lines of code are commented.
final
controller CodeLineEditingController?
Similar to TextField, editor uses CodeLineEditingController as the content controller.
final
findBuilder CodeFindBuilder?
Use this to build your own search widget. The search widget will appear on the top of editor field.
final
findController CodeFindController?
Controls the search widget and actions.
final
focusNode FocusNode?
Controls whether this widget has keyboard focus.
final
hashCode int
The hash code for this object.
no setterinherited
hint String?
Text that suggests what sort of input the field accepts.
final
indicatorBuilder CodeIndicatorBuilder?
Use this to build your own indicator widget like line number widget. See DefaultCodeLineNumber and DefaultCodeChunkIndicator.
final
key Key?
Controls how one widget replaces another widget in the tree.
finalinherited
margin EdgeInsetsGeometry?
The margin value of the whole editor, includes the addtional wdigets like line number widget.
final
onChanged ValueChanged<CodeLineEditingValue>?
Called when the user initiates a change to the editor's value was changed, such as insertion or deletion.
final
padding EdgeInsetsGeometry?
The padding of the editor field, excludes the addtional wdigets like line number widget.
final
readOnly bool?
Whether the text can be changed.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
scrollbarBuilder CodeScrollbarBuilder?
Use this to build your own scroll bar widget.
final
scrollController CodeScrollController?
Controls horizontal and vertical scrolling.
final
shortcutOverrideActions Map<Type, Action<Intent>>?
Override built-in shortcut key actions.
final
shortcutsActivatorsBuilder CodeShortcutsActivatorsBuilder?
Customize your shortcut keys.
final
showCursorWhenReadOnly bool?
Whether to show cursor when in readonly mode.
final
sperator Widget?
A sperator widget between indicator and editor field.
final
style CodeEditorStyle?
The style to use for the editor.
final
toolbarController SelectionToolbarController?
Controls the selection toolbar.
final
wordWrap bool?
Should wrap the word.
final

Methods

createElement() StatefulElement
Creates a StatefulElement to manage this widget's location in the tree.
inherited
createState() State<StatefulWidget>
Creates the mutable state for this widget at a given location in the tree.
override
debugDescribeChildren() List<DiagnosticsNode>
Returns a list of DiagnosticsNode objects describing this node's children.
inherited
debugFillProperties(DiagnosticPropertiesBuilder properties) → void
Add additional properties associated with the node.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toDiagnosticsNode({String? name, DiagnosticsTreeStyle? style}) DiagnosticsNode
Returns a debug representation of the object that is used by debugging tools and by DiagnosticsNode.toStringDeep.
inherited
toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) String
A string representation of this object.
inherited
toStringDeep({String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug}) String
Returns a string representation of this node and its descendants.
inherited
toStringShallow({String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) String
Returns a one-line detailed description of the object.
inherited
toStringShort() String
A short, textual description of this widget.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited