diff --git a/app/lib/pages/home_page.dart b/app/lib/pages/home_page.dart index 3663543f..dafa4859 100644 --- a/app/lib/pages/home_page.dart +++ b/app/lib/pages/home_page.dart @@ -103,6 +103,7 @@ class _HomePageState extends State { focusNode: _focusNode, autoFocus: false, readOnly: false, + placeholder: 'Add content', enableInteractiveSelection: true, expands: false, padding: EdgeInsets.zero, diff --git a/lib/models/documents/attribute.dart b/lib/models/documents/attribute.dart index d7865e7d..7b363bed 100644 --- a/lib/models/documents/attribute.dart +++ b/lib/models/documents/attribute.dart @@ -24,6 +24,7 @@ class Attribute { Attribute.link.key: Attribute.link, Attribute.color.key: Attribute.color, Attribute.background.key: Attribute.background, + Attribute.placeholder.key: Attribute.placeholder, Attribute.header.key: Attribute.header, Attribute.indent.key: Attribute.indent, Attribute.align.key: Attribute.align, @@ -53,6 +54,8 @@ class Attribute { static final BackgroundAttribute background = BackgroundAttribute(null); + static final PlaceholderAttribute placeholder = PlaceholderAttribute(); + static final HeaderAttribute header = HeaderAttribute(); static final IndentAttribute indent = IndentAttribute(); @@ -78,7 +81,8 @@ class Attribute { Attribute.strikeThrough.key, Attribute.link.key, Attribute.color.key, - Attribute.background.key + Attribute.background.key, + Attribute.placeholder.key, }; static final Set blockKeys = { @@ -222,6 +226,11 @@ class BackgroundAttribute extends Attribute { : super('background', AttributeScope.INLINE, val); } +/// This is custom attribute for hint +class PlaceholderAttribute extends Attribute { + PlaceholderAttribute() : super('placeholder', AttributeScope.INLINE, true); +} + class HeaderAttribute extends Attribute { HeaderAttribute({int level}) : super('header', AttributeScope.BLOCK, level); } diff --git a/lib/widgets/editor.dart b/lib/widgets/editor.dart index 3320b87c..29472aae 100644 --- a/lib/widgets/editor.dart +++ b/lib/widgets/editor.dart @@ -134,6 +134,7 @@ class QuillEditor extends StatefulWidget { final bool autoFocus; final bool showCursor; final bool readOnly; + final String placeholder; final bool enableInteractiveSelection; final double minHeight; final double maxHeight; @@ -154,6 +155,7 @@ class QuillEditor extends StatefulWidget { @required this.autoFocus, this.showCursor, @required this.readOnly, + this.placeholder, this.enableInteractiveSelection, this.minHeight, this.maxHeight, @@ -256,6 +258,7 @@ class _QuillEditorState extends State widget.scrollable, widget.padding, widget.readOnly, + widget.placeholder, widget.onLaunchUrl, ToolbarOptions( copy: true, diff --git a/lib/widgets/raw_editor.dart b/lib/widgets/raw_editor.dart index 0fa9cb3f..d1cadb0d 100644 --- a/lib/widgets/raw_editor.dart +++ b/lib/widgets/raw_editor.dart @@ -1,3 +1,5 @@ +import 'dart:convert'; + import 'package:flutter/cupertino.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/gestures.dart'; @@ -32,6 +34,7 @@ class RawEditor extends StatefulWidget { final bool scrollable; final EdgeInsetsGeometry padding; final bool readOnly; + final String placeholder; final ValueChanged onLaunchUrl; final ToolbarOptions toolbarOptions; final bool showSelectionHandles; @@ -58,6 +61,7 @@ class RawEditor extends StatefulWidget { this.scrollable, this.padding, this.readOnly, + this.placeholder, this.onLaunchUrl, this.toolbarOptions, this.showSelectionHandles, @@ -505,7 +509,8 @@ class RawEditorState extends EditorState Document _doc = widget.controller.document; if (_doc.isEmpty() && !widget.focusNode.hasFocus) { - _doc = Document()..insert(0, 'Place Holder'); + _doc = Document.fromJson(jsonDecode( + '[{"insert":"${widget.placeholder}"},{"attributes":{"placeholder":true},"insert":"\\n"}]')); } Widget child = CompositedTransformTarget( @@ -699,10 +704,6 @@ class RawEditorState extends EditorState ? defaultStyles.merge(parentStyles) : defaultStyles; - if (widget.controller.document.isEmpty()) { - _styles.merge(DefaultStyles(paragraph: defaultStyles.placeHolder)); - } - if (widget.customStyles != null) { _styles = _styles.merge(widget.customStyles); } diff --git a/lib/widgets/text_line.dart b/lib/widgets/text_line.dart index 1a2fd746..1ae101e9 100644 --- a/lib/widgets/text_line.dart +++ b/lib/widgets/text_line.dart @@ -88,6 +88,11 @@ class TextLine extends StatelessWidget { TextStyle textStyle = TextStyle(); + if (line.style.containsKey(Attribute.placeholder.key)) { + textStyle = defaultStyles.placeHolder.style; + return TextSpan(children: children, style: textStyle); + } + Attribute header = line.style.attributes[Attribute.header.key]; Map m = { Attribute.h1: defaultStyles.h1.style,