code_text_field
1.1.0, released 4 years ago by an unverified publisher
A customizable code text field supporting syntax highlighting and scrolling.
What it does
Provides a CodeField widget paired with a CodeController to parse and highlight text input according to a specified language or custom pattern/string maps. It supports vertical and horizontal scrolling, line numbers, and custom code modifiers.
AI-written summary of version 1.1.0, based on the package's README and metadata. Report an inaccuracy
Use it when
- You need to build a code editor inside your Flutter application
- You want real-time syntax highlighting for various programming languages
Skip it when
- You only need a standard single-line or multi-line text input without syntax highlighting
- You require complex IDE features like full language servers and deep code analysis
Strengths
- Supports 189 built-in languages and 90 themes via flutter_highlight
- Includes code modifiers for automatic indentation and tab management
- Supports both pattern-based and string-based custom parsing rules
Weaknesses
- Autocomplete disabling on Android does not work yet
- Limited to text input and syntax highlighting features rather than a full IDE
Setup
- Kind
- Flutter widgets
- Effort
- Low
- Code generation
- No
- Direct dependencies
- 3
Add the dependency to pubspec.yaml and optionally include a monospace font asset for proper code rendering.
import 'package:flutter/material.dart';
import 'package:code_text_field/code_text_field.dart';
import 'package:highlight/languages/dart.dart';
import 'package:flutter_highlight/themes/monokai-sublime.dart';
class CodeEditor extends StatefulWidget {
@override
_CodeEditorState createState() => _CodeEditorState();
}
class _CodeEditorState extends State<CodeEditor> {
CodeController? _codeController;
@override
void initState() {
super.initState();
final source = "void main() {\n print(\"Hello, world!\");\n}";
_codeController = CodeController(
text: source,
language: dart,
theme: monokaiSublimeTheme,
);
}
@override
void dispose() {
_codeController?.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return CodeField(
controller: _codeController!,
textStyle: TextStyle(fontFamily: 'SourceCode'),
);
}
}Alternatives
Packages that do the same job and could replace code_text_field.
- pin_code_fields
A customizable PIN and OTP input field widget for Flutter with headless core and Material support.
93Compare - sms_autofill
Flutter plugin to provide SMS code autofill support.
80Compare - searchfield
An autocomplete search widget with customizable suggestions, validation, and keyboard navigation.
79Compare - flutter_pin_code_fields
Generate customizable pin code fields for login pins or OTP inputs in Flutter.
50Compare
Works with
Packages commonly used together with code_text_field: ones it builds on, ones built on it, and its own family.
- highlightcode_text_field depends on itDart library that parses source code into syntax‑highlighted HTML
- flutter_highlightcode_text_field depends on itA Flutter widget that highlights source code with many languages and themes.
- linked_scroll_controllercode_text_field depends on itSynchronizes scroll positions of multiple scrollable widgets.