Toggles
Toggles are collapsible disclosure blocks with an always-visible single-line summary header and an expandable nested body story. Interactive readers can expand or collapse them on screen; static exports (DOCX and PDF) automatically expand collapsed toggles so printed output never loses content.
- Included in:
notesConfiguration,documentConfiguration - Pure-Dart import:
package:vyuh_document_elements/toggle.dartorpackage:vyuh_document_elements/vyuh_document_elements.dart - Flutter extension:
ToggleDocumentExtension(bundled inDocumentEditorElements.defaults) - Action namespace:
ToggleActions
Quick example
dart
import 'package:vyuh_document/vyuh_document.dart';
import 'package:vyuh_document_elements/vyuh_document_elements.dart';
final doc = Document.of(notesConfiguration, [
Toggle(
summary: 'Implementation details',
isExpanded: true,
blocks: [
Paragraph('Each toggle owns an isolated child story for its body blocks.'),
],
),
]);What you can configure
| Property | Type / Values | Purpose |
|---|---|---|
summary / header | Single-line editable header story | Always-visible disclosure title next to the chevron |
isExpanded | bool | Whether the nested body blocks are currently visible in interactive mode |
blocks | List<DocumentBlock> | Full nested body content (paragraphs, lists, code, images, nested toggles) |
styleId | String? | Optional named style binding |
Actions & commands
| Action ID | Effect |
|---|---|
ToggleActions.insert | Insert a new collapsible toggle block |
ToggleActions.toggleExpanded | Expand or collapse the active toggle |
- Typed commands:
SetToggleExpanded,SetToggleSummary— persisted canonically and fully undoable.
Restricting usage
- Remove toggles:
notesConfiguration.withoutElements([Toggle.element]) - Always expanded in print: Static PDF and DOCX export automatically expand collapsed toggles via the static expansion helper so archived documents contain every section.
Format parity
| DOCX | HTML | Markdown | |
|---|---|---|---|
| Expanded titled section preserving all nested blocks | Automatically expanded for complete static print output | Native <details><summary>...</summary>...</details> | <details><summary>...</summary>...</details> |