Document controls
The editor's chrome is built from a small set of controls: tool buttons, toolbar groups, menus, property fields, a dialog and a notice. They are public. A host that wants its own toolbar, side panel or dialog composes it from the same controls, and it matches the editor without restyling.
The controls gallery shows every control in each of its states, with the code to use it. Add &theme=dark or &theme=both to see it in dark or in both themes side by side.
dart
import 'package:vyuh_document_flutter/ui.dart';The controls do not need an editor or a controller. They read their colours from the ambient Theme, so mount them under the editor's chrome theme:
dart
Theme(
data: DocumentEditorTheme.light().materialTheme, // or .dark()
child: myToolbar,
)See Theming for a brand theme.
Tokens
Sizes, gaps and the corner radius are constants in the same library. Use them for your own layout so it lines up with the controls.
| Token | Value | Use |
|---|---|---|
documentTitleBarHeight | 36 | Row one: title, menus, mode switches |
documentToolbarRowHeight | 40 | The tools row |
documentRibbonToolSize | 32 | One tool target |
documentChromeControlHeight | 28 | Inputs, dropdowns and action buttons outside the tools row |
documentChromePanelHeaderHeight | 40 | The header of a side panel or dialog |
documentRibbonIconSize | 19 | A toolbar glyph |
documentRibbonMenuRowIconSize | 16 | A glyph in a menu row |
documentRibbonSectionGap | 8 | Between groups |
documentRibbonControlGap | 4 | Between controls in a group |
documentRibbonControlInset | 8 | Inside a control |
documentToolbarWellInset | 2 | Between tools in a toolbar group |
documentDialogInset | 16 | Inside a dialog |
documentChromeSurfaceInset | 24 | Inside a full-surface view |
documentRibbonSurfaceRadius | 4 | Every control surface |
documentChromeHairline | 1 | Dividers and seams |
documentChromeDisabledOpacity | 0.38 | An unavailable control |
Colours come from the theme's ColorScheme: surface and surfaceContainer for fills, onSurface and onSurfaceVariant for text and glyphs, primary for the active state, outlineVariant and the theme's dividerColor for rules.
Buttons
| Control | Use it for |
|---|---|
DocumentIconButton | One tool: a glyph with a tooltip. active marks a toggled tool. |
DocumentActionButton | A labelled action. .filled for the primary action, .outlined for the secondary one, .text for a quiet one. |
RibbonMenuButton | A split tool: the face applies the current choice, the caret opens the others. |
A null onPressed disables a button. Icons come from DocumentSemanticIcons, which names glyphs by document concept.
dart
DocumentIconButton(
icon: DocumentSemanticIcons.bold,
tooltip: 'Bold',
active: isBold,
onPressed: canToggle ? () async => toggleBold() : null,
)
DocumentActionButton.filled(
label: 'Insert',
onPressed: () async => insert(),
)
RibbonMenuButton(
label: 'Bulleted list',
icon: DocumentSemanticIcons.bulletedList,
enabled: canList,
active: inList,
onPressed: toggleList,
menuItems: [
CdxMenuAction(title: 'Disc', onTap: () => setMarker(disc)),
CdxMenuAction(title: 'Circle', onTap: () => setMarker(circle)),
],
)Toolbar
| Control | Use it for |
|---|---|
DocumentToolbarGroup | A flat group of tools. leadingDivider draws the hairline before a group that follows another. |
DocumentToolbarGroupDivider | That hairline alone. |
DocumentToolbarMenuButton | A menu button in a tools row: icon-only, or labelled with showLabel. |
DocumentRibbonDropdownTrigger | The face of a menu button: label, glyph and chevron. Presentation only. |
Groups have no background. Space and the hairline separate them; fill is for hover, press and the active state of the tools inside.
dart
SizedBox(
height: documentToolbarRowHeight,
child: Row(
spacing: documentRibbonSectionGap,
children: [
DocumentToolbarGroup(label: 'History', children: [undo, redo]),
DocumentToolbarGroup(
label: 'Marks',
leadingDivider: true,
children: [bold, italic, underline],
),
DocumentToolbarGroup(
label: 'Lists',
leadingDivider: true,
children: [
bullets,
numbers,
DocumentToolbarMenuButton(
label: 'List options',
icon: DocumentSemanticIcons.list,
items: () => listOptionItems,
),
],
),
],
),
)To let the editor build the toolbar from its actions instead, see Toolbar shapes.
Menus
Every menu takes the same items: CdxMenuAction, CdxMenuSubmenu, CdxMenuDivider and CdxMenuHeader. An action without onTap is shown as unavailable.
| Control | Use it for |
|---|---|
DocumentDropdown<T> | Picking one value from a list. A null onChanged disables it. |
DocumentActionMenu | A labelled menu button over a list of commands. |
DocumentMenuAdapter | A menu under a trigger of your own. |
DocumentContextMenu | A region that opens a menu at the pointer on right-click or long-press. |
RibbonChoicePanel<T> | A grid of previewed choices inside a popup: alignments, border presets, shapes. |
dart
DocumentDropdown<String>(
semanticLabel: 'Paragraph style',
value: style,
options: const [
CdxMenuOption(value: 'normal', title: 'Normal'),
CdxMenuOption(value: 'h1', title: 'Heading 1'),
],
onChanged: (value) => setStyle(value),
triggerBuilder: (context, state) => DocumentRibbonDropdownTrigger(
label: state.selectedLabel ?? 'Style',
isOpen: state.isOpen,
),
)
DocumentActionMenu(
label: 'Insert',
icon: DocumentSemanticIcons.add,
items: [
const CdxMenuHeader(title: 'Blocks'),
CdxMenuAction(title: 'Table', shortcut: 'Ctrl+Alt+T', onTap: insertTable),
const CdxMenuDivider(),
CdxMenuSubmenu(
title: 'Break',
items: [CdxMenuAction(title: 'Page break', onTap: pageBreak)],
),
],
)
DocumentContextMenu(
items: [
CdxMenuAction(title: 'Copy', onTap: copy),
CdxMenuAction(title: 'Paste', onTap: paste),
],
child: page,
)Fields and properties
Mount property fields under DocumentPropertyPanelTheme. It gives every field the panel's compact typography and input style.
| Control | Use it for |
|---|---|
DocumentPropertySection | A titled, collapsible group of fields. |
DocumentPropertyNumber | A typed number with a unit and step controls. A DocumentPropertyNumberSpec owns range, step and unit. |
DocumentPropertyText, DocumentPropertyTextArea | One line of text, or several. |
DocumentBooleanField, DocumentPropertySwitchField | An on/off property as a labelled row. |
DocumentPropertySegmentedChoice<T> | Two to four exclusive choices shown at once, beside a label. |
DocumentPropertySegmentedTabs<T> | The segmented strip alone. unavailableReason disables a segment and says why. |
DocumentPropertyFieldRow | The label-and-control row, for a control of your own. |
DocumentDisclosure | A header that shows or hides rarely needed options. |
dart
DocumentPropertyPanelTheme(
child: DocumentPropertySection(
title: 'Spacing',
children: [
DocumentPropertyNumber(
label: 'Before',
value: spaceBefore,
spec: const DocumentPropertyNumberSpec(
minimum: 0,
maximum: 72,
step: 1,
),
onChanged: setSpaceBefore,
),
DocumentBooleanField(
label: 'Keep with next',
value: keepWithNext,
onChanged: setKeepWithNext,
),
],
),
)For the editor's own Properties panel, see Property inspector.
Panels and dialogs
| Control | Use it for |
|---|---|
DocumentPropertyPanelHeader | The header of a side panel: glyph, name, close, and a breadcrumb row with an optional back button. |
DocumentDialogShell | The editor's dialog: a title with a close button, a body and a right-aligned action row. |
showDocumentDialog | Opens a DocumentDialogShell as a route. |
dart
showDocumentDialog<void>(
context: context,
builder: (context) => DocumentDialogShell(
title: 'Insert link',
actions: [
DocumentActionButton.text(
label: 'Cancel',
onPressed: () async => Navigator.of(context).pop(),
),
DocumentActionButton.filled(label: 'Insert', onPressed: insert),
],
child: linkFields,
),
)Notices and status
| Control | Use it for |
|---|---|
DocumentTopNotice | One line above the document that reports what just happened. tone is info, warning (the default) or success. |
DocumentDropFeedback | What releasing a dragged file would do, drawn over the surface it is dragged across. tone is accept (the default), neutral or refuse. |
DocumentStatusBar | The strip under the editor: the page in view, the word count, an optional live language picker (locale, supportedLocales, onLocaleChanged; see Localization), a pages-or-pageless toggle (onPagelessChanged), and zoom at its trailing edge (zoom), whose menu also lists one page, two pages and grid (onCanvasLayoutModeChanged). It reads an editor controller. |
DocumentZoomControl | Zoom out, the percentage with its presets and fits, zoom in. The status bar mounts it; use it on its own over any DocumentZoomCapability. |
A notice always has a dismiss button. actionLabel and onAction add one action beside it. docked: false draws the notice as a card of its own instead of a bar under the toolbar.
dart
DocumentTopNotice(
message: 'Exported to quarterly-report.pdf.',
tone: DocumentTopNoticeTone.success,
actionLabel: 'Show file',
onAction: revealExport,
onDismiss: clearNotice,
)Drop feedback
The editor shows a drop state while a file is dragged over it: a document its host opens veils the canvas with "Drop to open", an image shows the insertion seam on the page where it will land, and a file it does not take shows "Can't drop here" with the reason and answers the platform with no drop. Pass the editor a DocumentDropHost to say which documents you open; DocumentImportDropHost builds one from the import formats you install.
dart
final documentDrop = DocumentImportDropHost(
onOpen: (file, format) => openBytes(file.fileName, format, file.bytes),
);
DocumentRuntimeEditor(controller: controller, documentDrop: documentDrop)What a platform says during a drag differs. A desktop drag carries each file's name, so the type is known before the drop. A browser drag carries only a media type: the name and the bytes arrive with the drop. A file the browser has no type for (often Markdown) shows the neutral "Drop file" state, and a refusal is then reported in a notice after the drop.
Use DocumentDropFeedback for a drop target of your own. It fills its parent, takes no pointer events and is announced as a live region, so put it in the same Stack as the surface and build it only while a drag is over that surface. DocumentDropFeedback.hint draws the message at the bottom edge and leaves the surface clear.
dart
Stack(
children: [
surface,
if (draggingDocument)
const Positioned.fill(
child: DocumentDropFeedback(
title: 'Drop to open',
detail: 'Opens this DOCX document.',
icon: DocumentSemanticIcons.importDocument,
),
),
],
)States
Hover, press and keyboard focus need no code: every control draws them. You set three states yourself:
- Active:
active: trueon a tool,selectedon a menu action,valueon a field. - Disabled: a null
onPressedoronChanged, orenabled: false. A disabled control draws atdocumentChromeDisabledOpacityand ignores the pointer and the keyboard. - Loading:
isLoading: trueon aDocumentActionButton.
A menu trigger draws its open state while its menu is up.