placeholder function

Extension placeholder(
  1. Object content
)

Extension that enables a placeholder—a piece of example content to show when the editor is empty.

Example

EditorState.create(EditorStateConfig(
  extensions: placeholder('Enter some text...'),
))

The content can be:

  • A String that will be displayed as gray placeholder text
  • A Widget that will be cloned and displayed
  • A function Widget Function(EditorViewState) for dynamic content

Implementation

Extension placeholder(Object content) {
  final plugin = ViewPlugin.define<_PlaceholderPluginValue>(
    (view) => _PlaceholderPluginValue(view, content),
    ViewPluginSpec(
      decorations: (v) => v.decorations,
    ),
  );

  // For string content, also add aria-placeholder attribute
  if (content is String) {
    return ExtensionList([
      plugin.extension,
      contentAttributes.of({'aria-placeholder': content}),
    ]);
  }
  return plugin.extension;
}