Skip to content
pubscout

code_text_field

1.1.0, released 4 years ago by an unverified publisher

A customizable code text field supporting syntax highlighting and scrolling.

WASM-ready
$ flutter pub add code_text_field
Source repository

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.

Works with

Packages commonly used together with code_text_field: ones it builds on, ones built on it, and its own family.