live_markdown_editor 0.7.2 copy "live_markdown_editor: ^0.7.2" to clipboard
live_markdown_editor: ^0.7.2 copied to clipboard

A source-preserving Flutter Markdown editor with raw, live, and read modes.

live_markdown_editor #

A source-preserving, Obsidian-inspired Markdown editor for Flutter with three modes — Raw (literal source), Live (formatted with hidden delimiters, revealed at caret/selection), and Read (delimiter-free, selectable).

The editor is package-owned: its custom editable engine uses only Flutter foundation, services, widgets, and rendering layers (zero Material or Cupertino dependencies in lib/). On desktop and mobile, selection menus are the platform's own native system menus; on web, the browser owns selection and context menus natively.


Supported Platforms #

Platform Selection Menu Mechanism Native Menu Manually Tested
Android Floating ActionMode toolbar Yes
Linux GTK popover menu (GtkMenu) Yes
Web Browser-owned DOM selection & context menu Browser
iOS UIEditMenuInteraction / UIMenuController Yes
macOS Native NSMenu popup Yes
Windows Win32 TrackPopupMenuEx Yes

Note: On mobile and desktop, native menus never render under the keyboard or off-screen. On Web, the editor coordinates with the browser engine's text input connection for genuine browser-native context menus and copy/paste.


Supported Markdown Syntax #

Syntax Markdown Pattern Live Mode Presentation
Paragraphs Plain text with words Preserves source, wraps naturally
Headings (H1–H6) # H1 through ###### H6 Styled heading scales; # revealed at caret
Bold **bold** or __bold__ Bold weight; delimiters revealed at selection
Italic *italic* or _italic_ Italic style; delimiters revealed at selection
Strikethrough ~~strikethrough~~ Strikethrough line; delimiters revealed at caret
Highlight ==highlight== Highlight tint background; delimiters revealed
Inline Code `code` or code Monospace font with subtle background pill
Fenced Code Blocks ```dart ... ``` Monospace block with background fill
Blockquotes > Quoted line Left border accent decoration with inset text
Unordered Lists - Item or * Item or + Item Bullet markers with smart list continuation
Ordered Lists 1. Item or 2. Item Decimal numerals with auto-increment on Enter
Task Lists - [ ] Pending, - [x] Done, or 1. [ ] Ordered Interactive checkbox widgets (toggle in-place; ordered numbers stay visible, marker reveals at the caret)
Horizontal Rules --- or *** or ___ Rendered divider line decoration
Links [Label](https://...) or [Label](url "Title") Clickable/tappable link with URL tap callback
Tables GFM pipe tables: ` a

Installation #

Add live_markdown_editor to your pubspec.yaml:

dependencies:
  live_markdown_editor: ^0.6.0

Or run:

flutter pub add live_markdown_editor

Quick Start #

import 'package:flutter/widgets.dart';
import 'package:live_markdown_editor/live_markdown_editor.dart';

class MyEditorPage extends StatefulWidget {
  const MyEditorPage({super.key});

  @override
  State<MyEditorPage> createState() => _MyEditorPageState();
}

class _MyEditorPageState extends State<MyEditorPage> {
  late final MarkdownEditorController _controller = MarkdownEditorController(
    text: '# My Notes\n\n- [ ] Ship to production\n- [x] Write tests',
  );

  @override
  void dispose() {
    _controller.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return LiveMarkdownEditor(
      controller: _controller,
      onChanged: (markdown) => print('Saved: $markdown'),
      onLinkTap: (url) => print('Open: $url'),
    );
  }
}

Modes #

The canonical source of truth is always controller.text (UTF-16 TextEditingValue). Modes differ only in visual projection and delimiter visibility:

Mode Property Behavior
Raw MarkdownEditorMode.raw Displays literal Markdown source code without hiding any delimiters.
Live MarkdownEditorMode.live Formats text visually, renders task boxes as interactive widgets, and reveals delimiters only when the caret or selection touches them.
Read MarkdownEditorMode.read Delimiter-free reading view. Preserves text selection, link taps, and in-place task checkbox toggling.

Switch modes smoothly at runtime without losing selection, undo history, or scroll position:

_controller.mode = MarkdownEditorMode.read;

Customization & Advanced Usage #

1. Theme Configuration (MarkdownEditorThemeData) #

Customize all visual properties (colors, typography, heading scales, task sizing, blockquote margins) using MarkdownEditorThemeData:

LiveMarkdownEditor(
  controller: _controller,
  theme: MarkdownEditorThemeData.light().copyWith(
    accentColor: const Color(0xFFC03A1E),
    backgroundColor: const Color(0xFFFBF6E9),
    textColor: const Color(0xFF221C10),
    bodyStyle: const TextStyle(
      fontSize: 17,
      height: 1.7,
      fontFamily: 'IBMPlexSans',
    ),
    taskCheckedColor: const Color(0xFFC03A1E),
    quoteBorderColor: const Color(0xFFC9BBA0),
    quoteBorderWidth: 3.0,
    contentPadding: const EdgeInsets.symmetric(horizontal: 32, vertical: 24),
  ),
)

2. Replaceable Component Builders (MarkdownEditorComponentBuilders) #

Customize task checkboxes or selection handle presentation while maintaining package-owned gestures and geometry:

LiveMarkdownEditor(
  controller: _controller,
  componentBuilders: MarkdownEditorComponentBuilders(
    // Inject a custom task toggle widget (e.g. Material Checkbox or CupertinoSwitch):
    taskToggleBuilder: (context, taskContext) => Checkbox(
      value: taskContext.checked,
      onChanged: taskContext.enabled ? (_) => taskContext.onToggle() : null,
    ),
  ),
)

3. Editing Behavior (MarkdownEditingBehavior) #

Control typing auto-pairing, wrapping, and list continuations:

LiveMarkdownEditor(
  controller: _controller,
  behavior: const MarkdownEditingBehavior(
    autoPair: true,           // Auto-pairs delimiters like **, ``, _, ~~
    wrapSelection: true,      // Typing a delimiter around selected text wraps it
    smartLists: true,         // Enter on a list/task item auto-continues the list
    autoCloseFences: true,    // Triple backticks auto-closes the code fence block
  ),
)

4. Bidi & RTL Direction (directionMode) #

Supports per-line first-strong bidirectional text shaping:

LiveMarkdownEditor(
  controller: _controller,
  // MarkdownDirectionMode.aware resolves direction independently per hard line:
  directionMode: MarkdownDirectionMode.aware,
  fallbackDirection: TextDirection.ltr,
)
  • MarkdownDirectionMode.aware (default): Analyzes first-strong letters of each line independently (ideal for mixed Arabic/English documents).
  • MarkdownDirectionMode.auto: Computes document-level direction.
  • MarkdownDirectionMode.ltr / MarkdownDirectionMode.rtl: Forces a fixed text direction.

5. Programmatic Commands & Undo/Redo #

Execute atomic, undoable formatting transactions directly on the controller:

// Formatting commands
_controller.execute(MarkdownCommand.bold);
_controller.execute(MarkdownCommand.italic);
_controller.execute(MarkdownCommand.strikethrough);
_controller.execute(MarkdownCommand.code);
_controller.execute(MarkdownCommand.link, argument: 'https://flutter.cn');
_controller.execute(MarkdownCommand.taskList);
_controller.execute(MarkdownCommand.blockquote);

// History control
if (_controller.canUndo) _controller.undo();
if (_controller.canRedo) _controller.redo();

Example App #

Check out example/ for the Editor Studio, an editor-first responsive demonstration featuring:

  • A full-height mobile writing surface with one compact mode toolbar
  • On-demand documents, editor settings, theme, and platform preview tools
  • Cool-neutral light and dark themes with cohesive Latin/Arabic typography
  • Foundation by default, with Material and Cupertino previews that share the same canonical editor source
  • Adaptive phone, tablet, and desktop layouts backed by visual regression tests

To run the demo:

cd example
flutter run

License #

MIT License — see LICENSE for details.

3
likes
0
points
746
downloads

Publisher

unverified uploader

Weekly Downloads

A source-preserving Flutter Markdown editor with raw, live, and read modes.

Homepage
Repository (GitLab)
View/report issues

Topics

#markdown #editor #text-editor #flutter #widget

License

unknown (license)

Dependencies

flutter, native_adaptive_toolbox

More

Packages that depend on live_markdown_editor