How bansalgaurav852/flutter-quill works
1. What this repo is
This is a Flutter monorepo centered on a rich text editor package, flutter_quill, plus a companion package, flutter_quill_extensions, and a full multi-platform example app. There is no backend or networked service layer; the core architecture is a client-side editor runtime.
2. Top-level package boundaries
The main package lives under lib/ and exposes the public API through lib/flutter_quill.dart and lib/extensions.dart. Most implementation details are hidden under lib/src/, which is split into models, editor widgets, utilities, themes, and translations. The extension package is a separate boundary for optional embed support.
3. Document and data model layer
The editor uses Quill’s Delta-based document model. Key types are in lib/src/models/documents/ and lib/src/models/quill_delta.dart: Document, Delta, Attribute, History, and the node hierarchy (block, line, leaf, embeddable, container, node). This layer is the source of truth for content, formatting, and undo/redo state.
4. Editing pipeline
User actions are mediated by QuillController in lib/src/widgets/controller.dart. The controller sits between the UI and the document model, applying insert/format/delete rules from lib/src/models/rules/. The main flow is: input event → controller mutation → document/delta update → widget rebuild.
5. Editor rendering and interaction
The main editing surface is in lib/src/widgets/editor.dart and raw_editor/. These widgets handle text input, cursor movement, selection, keyboard handling, and visual composition. Supporting widgets like text_block.dart, text_line.dart, cursor.dart, float_cursor.dart, and text_selection.dart render and manage the editor surface.
6. Toolbar and command surface
The toolbar subsystem in lib/src/widgets/toolbar/ provides the command layer for formatting and document operations: styles, headers, color, font family/size, alignment, lists, links, history, indent, search, and checklist toggles. Toolbar actions operate on the same QuillController, so the toolbar is not separate state; it is a command UI over the document model.
7. Styling, themes, and localization
Visual configuration is handled by models in lib/src/models/themes/ and default widget styles in lib/src/widgets/default_styles.dart. Text and toolbar labels are localized through lib/src/translations/toolbar.i18n.dart and lib/translations.dart, with locale selection supported by both editor and toolbar widgets.
8. Embed architecture
Embeds are a first-class extension point but not all embed implementations live in the core package. The core editor supports embed nodes abstractly via embeddable.dart, embeds.dart, and the embed-related widget layer. Concrete image/video/formula implementations are split into flutter_quill_extensions/lib/embeds/, which provides:
- embed builders for rendering,
- toolbar buttons for inserting media,
- utilities for picking media,
- specialized widgets for image/video/YouTube/formula display.
9. Serialization and persistence
Content is represented internally as Quill Delta and can be serialized to JSON. The README indicates the normal persistence path is document.toDelta().toJson() and restoration via Document.fromJson(...). So the storage boundary is JSON delta, not a custom app-specific format.
10. Platform-specific integration points
The editor is cross-platform, but media insertion depends on platform-specific picker implementations. The README and example show different hooks for web versus desktop/mobile: web needs custom image/embed builders and web image selection logic, while desktop needs file-pick implementations for toolbar image actions. This is why embed/media handling is delegated to the example and extension package rather than hardcoded in the core.
11. Example app as the integration reference
The example/ app is a full Flutter application that demonstrates how the package is meant to be composed. Its lib/pages/home_page.dart and read_only_page.dart likely showcase editable and view-only editor configurations. widgets/demo_scaffold.dart and widgets/responsive_widget.dart suggest the demo adapts layout to screen size and platform.
12. Example platform shells
The example includes standard Flutter runners for Android, iOS, web, macOS, Linux, and Windows. These folders are mostly platform scaffolding; the actual editor behavior still comes from the shared Dart code in example/lib/. The universal_ui/ layer is specifically there to abstract platform differences in UI/picking behavior.
13. Assets and demo data
example/assets/ contains sample JSON documents and fonts. These are part of the demo content pipeline: they let the example load prebuilt Quill documents and demonstrate font-family customization without any server dependency.
14. Overall architecture in one sentence
The repo is a layered Flutter editor system: a Delta-based document model and command controller at the core, rendering and input widgets around it, optional embed/media implementations in a separate extensions package, and a multi-platform example app that wires the pieces together.
Main entry points: editor.dart Editor surface · flutter_quill.dart Public API · controller.dart Controller · toolbar.dart Toolbar
Components 20
Core package
Primary Flutter rich-text editor package and internal runtime.
- Public API · Package entrypoints that expose the editor and extension surface.
lib/flutter_quill.dart - Document model · Delta-based source of truth for content, formatting, and history.
lib/src/models/documents/document.dart - Quill Delta · Delta representation used for persistence and JSON interchange.
lib/src/models/quill_delta.dart - Edit rules · Insert, delete, and format rules applied during controller mutations.
lib/src/models/rules/rule.dart - Controller · Coordinates user actions, document mutations, and selection state.
lib/src/widgets/controller.dart - Editor surface · Main editable widget layer that composes input, selection, and document display.
lib/src/widgets/editor.dart - Raw editor · Low-level text input, cursor, and selection integration for the editor.
lib/src/widgets/raw_editor/raw_editor_state_text_input_client_mixin.dart - Text layout · Block, line, cursor, and selection widgets used to render editable content.
lib/src/widgets/text_block.dart - Toolbar · Formatting and document-operation controls that act on the controller.
lib/src/widgets/toolbar.dart - Styles & theme · Default styles, icon/dialog themes, and visual configuration models.
lib/src/widgets/default_styles.dart - Translations · Localized labels and toolbar strings for editor and toolbar widgets.
lib/translations.dart - Core embeds · Abstract embed nodes and editor-side embed handling in the core package.
lib/src/widgets/embeds.dart
Extensions package
Optional embed/media support packaged separately from core.
- Extensions API · Public entrypoint for optional media/embed extensions.
flutter_quill_extensions/lib/flutter_quill_extensions.dart - Embed builders · Concrete builders for image, video, and YouTube embed rendering.
flutter_quill_extensions/lib/embeds/builders.dart - Media toolbar · Buttons and helpers for inserting camera, image, video, and formula embeds.
flutter_quill_extensions/lib/embeds/toolbar/image_button.dart - Media widgets · Specialized widgets for image resizing, video playback, and YouTube embeds.
flutter_quill_extensions/lib/embeds/widgets/image.dart
Example app
Multi-platform demo wiring the editor into a Flutter application.
- Example app · Cross-platform demo application showing editable and read-only editor setups.
example/lib/main.dart - Editor pages · Primary demo pages for editable and read-only editor configurations.
example/lib/pages/home_page.dart - Universal UI · Abstraction layer for platform-specific picker and UI behavior in the demo.
example/lib/universal_ui/universal_ui.dart - Demo assets · Sample JSON documents and fonts used by the example app.
example/assets/sample_data.json
Connections 27
- Public API → Document model: exposes · Public package API re-exports the document layer.
- Public API → Controller: exposes · Public package API exposes editor/controller primitives.
- Public API → Editor surface: exposes · Public package API exposes the main editor widgets.
- Public API → Toolbar: exposes · Public package API exposes toolbar components.
- Document model → Quill Delta: serializes to · Documents are converted to Delta JSON for persistence.
- Edit rules → Controller: governs · Mutation rules shape how controller edits are applied.
- Controller → Document model: mutates · Controller applies document changes and selection updates.
- Editor surface → Raw editor: delegates input · Editor surface delegates text input and selection handling to raw editor layers.
- Editor surface → Text layout: composes · Editor surface is built from text layout and interaction widgets.
- Editor surface → Core embeds: renders embeds · Editor surface hosts abstract embed nodes.
- Toolbar → Controller: issues commands · Toolbar actions operate on the shared controller state.
- Styles & theme → Editor surface: styles · Default theme and style models configure editor appearance.
- Styles & theme → Toolbar: styles · Theme models also configure toolbar presentation.
- Translations → Toolbar: localizes · Translation strings feed toolbar labels and dialogs.
- Translations → Editor surface: localizes · Localization is shared by editor-facing widgets.
- Extensions API → Embed builders: exports · Extensions package exposes embed rendering builders.
- Extensions API → Media toolbar: exports · Extensions package exposes media insertion toolbar controls.
- Extensions API → Media widgets: exports · Extensions package exposes specialized media widgets.
- Embed builders → Core embeds: implements · Concrete builders attach to the core embed abstraction.
- Media toolbar → Toolbar: extends · Media actions plug into the shared toolbar/controller command surface.
- Media widgets → Core embeds: specializes · Media widgets render concrete embed types supported by the core editor.
- Example app → Public API: uses · Example app depends on the core editor package.
- Example app → Extensions API: uses · Example app depends on optional extension package features.
- Example app → Editor pages: navigates · App routes to editable and read-only demo pages.
- Editor pages → Controller: configures · Demo pages configure the controller and editor behavior.
- Editor pages → Universal UI: bridges platform · Demo pages rely on platform-abstracted UI and picker hooks.
- Example app → Demo assets: loads · Demo loads sample documents and fonts from assets.