CodeForge class
A highly customizable code editor widget for Flutter.
CodeForge provides a feature-rich code editing experience with support for:
- Syntax highlighting for multiple languages
- Code folding
- Line numbers and gutter
- Auto-indentation and bracket matching
- LSP (Language Server Protocol) integration
- AI code completion
- Undo/redo functionality
- Search highlighting
Example:
final controller = CodeForgeController();
CodeForge(
controller: controller,
language: langDart,
enableFolding: true,
enableGutter: true,
textStyle: TextStyle(
fontFamily: 'JetBrains Mono',
fontSize: 14,
),
)
- Inheritance
-
- Object
- DiagnosticableTree
- Widget
- StatefulWidget
- CodeForge
Constructors
-
CodeForge({Key? key, CodeForgeController? controller, UndoRedoController? undoController, Map<
String, TextStyle> ? editorTheme, Mode? language, CodeForgeFeatures codeForgeFeatures = const CodeForgeFeatures(), CodeForgeStyling codeForgeStyling = const CodeForgeStyling(), String? filePath, String? fileUrl, String? initialText, String? fileUri, FocusNode? focusNode, ScrollController? verticalScrollController, ScrollController? horizontalScrollController, ScrollPhysics verticalScrollPhysics = const ClampingScrollPhysics(), EdgeInsets? innerPadding, int backgroundOpacity = 255, CodeForgeKeyboardShortcuts keyboardShotcuts = const CodeForgeKeyboardShortcuts(), List<CustomCodeSnippet> ? customCodeSnippets, List<CustomContextMenu> ? customContextMenuItems, int? tabSize, TextInputType keyboardType = TextInputType.multiline, TextDirection textDirection = TextDirection.ltr, ScrollbarDecoration? scrollbarDecoration, GutterBuilder? gutterBuilder, LspSuggestionBuilder? lspSuggestionBuilder, List<Mode> extraLanguages = const [], PreferredSizeWidget finderBuilder(BuildContext context, FindController findController)?, FindController? findController}) - Creates a CodeForge code editor widget.
-
CodeForge.plainTextField({Key? key, CodeForgeController? controller, UndoRedoController? undoController, Map<
String, TextStyle> ? editorTheme, Mode? language, CodeForgeFeatures codeForgeFeatures = const CodeForgeFeatures(enableGutter: false, enableGuideLines: false, enableFolding: false, enableMinimap: false, enableBracketPairMatching: false), CodeForgeStyling codeForgeStyling = const CodeForgeStyling(), String? filePath, String? fileUrl, String? initialText, String? fileUri, FocusNode? focusNode, ScrollController? verticalScrollController, ScrollController? horizontalScrollController, ScrollPhysics verticalScrollPhysics = const ClampingScrollPhysics(), EdgeInsets? innerPadding, int backgroundOpacity = 255, CodeForgeKeyboardShortcuts keyboardShotcuts = const CodeForgeKeyboardShortcuts(), List<CustomCodeSnippet> ? customCodeSnippets, List<CustomContextMenu> ? customContextMenuItems, int? tabSize, TextInputType keyboardType = TextInputType.multiline, TextDirection textDirection = TextDirection.ltr, ScrollbarDecoration? scrollbarDecoration, GutterBuilder? gutterBuilder, LspSuggestionBuilder? lspSuggestionBuilder, List<Mode> extraLanguages = const [], PreferredSizeWidget finderBuilder(BuildContext context, FindController findController)?, FindController? findController}) -
Use CodeForge as a powerful alternative to the default
TextField, without any IDE features.
Properties
- backgroundOpacity → int
-
The opacity of the background color.
Falls in the range0-255.
final - codeForgeFeatures → CodeForgeFeatures
-
override the
codeForgeFeaturesparameter in the CodeForge class to toggle/overrideboolfeature flags, such asreadOnly,autoFocus,enableGutter, etc.final - codeForgeStyling → CodeForgeStyling
-
override the
codeForgeStylingparameter in the CodeForge class to customize various parts of the editor.final - controller → CodeForgeController?
-
The controller for managing the editor's text content and selection.
final
-
customCodeSnippets
→ List<
CustomCodeSnippet> ? -
A list of custom code snippets that appear in the suggestion popup.
final
-
customContextMenuItems
→ List<
CustomContextMenu> ? -
Include custom items in the context menu (The menu appearson right click).
final
-
editorTheme
→ Map<
String, TextStyle> ? -
The syntax highlighting theme as a map of token types to TextStyle.
final
-
extraLanguages
→ List<
Mode> -
Additional language modes registered in the same highlighter instance.
final
- filePath → String?
-
The file path for LSP features.
final
- fileUri → String?
-
Especially for web.
The file URI for LSP features (e.g., 'file:///workspace/main.dart').final - fileUrl → String?
-
A raw file URL to load content from (e.g., GitHub raw URL).
final
- findController → FindController?
-
The finder controller for managing search functionality.
final
- finderBuilder → PreferredSizeWidget Function(BuildContext context, FindController findController)?
-
Builder for a custom Finder widget.
final
- focusNode → FocusNode?
-
The focus node for managing keyboard focus.
final
- gutterBuilder → GutterBuilder?
-
Can be used to build gutter with custom content instead of line numbers.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- horizontalScrollController → ScrollController?
-
Custom scroll controller for horizontal scrolling.
final
- initialText → String?
-
Initial text content for the editor.
final
- innerPadding → EdgeInsets?
-
Padding inside the editor content area.
final
- key → Key?
-
Controls how one widget replaces another widget in the tree.
finalinherited
- keyboardShotcuts → CodeForgeKeyboardShortcuts
-
Keyboard shortcuts used by the CodeForge editor.
Most of the keyboard shortcuts, except the core operations like cut, copy, paste, select all, undo, redo can be modified by editing the hardcoded shortcuts defined in theCodeForgeKeyboardShotcutsclass.
eg:final - keyboardType → TextInputType
-
The type of the virtual keyboard that will used by the CodeForge.
final
- language → Mode?
-
The programming language mode for syntax highlighting.
Determines which language syntax rules to apply.final - lspSuggestionBuilder → LspSuggestionBuilder?
-
Builds custom content for each LSP completion suggestion.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- scrollbarDecoration → ScrollbarDecoration?
-
Customize the scroll appearance.
Currently included vertical scrollbar only.
final
- tabSize → int?
-
Custom tabSize for the editor.
Defaults to 1 if using
\t, or 2 if using space, by setting theuseSpaceAsTabtotruefinal - textDirection → TextDirection
-
The text direction for the editor's content.
final
- undoController → UndoRedoController?
-
The controller for managing undo/redo operations.
final
- verticalScrollController → ScrollController?
-
Custom scroll controller for vertical scrolling.
final
- verticalScrollPhysics → ScrollPhysics
-
The scroll physics that can be used to modify the vertical scroll behaviour of the editor.
Defaults to ClampingScrollPhysics.
The horizontal scroll physics cannot be modified because CodeForge internally uses a custom scroll physics for RTL support.final
Methods
-
createElement(
) → StatefulElement -
Creates a StatefulElement to manage this widget's location in the tree.
inherited
-
createState(
) → State< CodeForge> -
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, int wrapWidth = 65}) → 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