Implement the rest

pull/34/head
singerdmx 4 years ago
parent 76ae6dedc6
commit 07960380f2
  1. 1
      app/lib/pages/home_page.dart
  2. 11
      lib/models/documents/attribute.dart
  3. 3
      lib/widgets/editor.dart
  4. 11
      lib/widgets/raw_editor.dart
  5. 5
      lib/widgets/text_line.dart

@ -103,6 +103,7 @@ class _HomePageState extends State<HomePage> {
focusNode: _focusNode,
autoFocus: false,
readOnly: false,
placeholder: 'Add content',
enableInteractiveSelection: true,
expands: false,
padding: EdgeInsets.zero,

@ -24,6 +24,7 @@ class Attribute<T> {
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<T> {
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<T> {
Attribute.strikeThrough.key,
Attribute.link.key,
Attribute.color.key,
Attribute.background.key
Attribute.background.key,
Attribute.placeholder.key,
};
static final Set<String> blockKeys = {
@ -222,6 +226,11 @@ class BackgroundAttribute extends Attribute<String> {
: super('background', AttributeScope.INLINE, val);
}
/// This is custom attribute for hint
class PlaceholderAttribute extends Attribute<bool> {
PlaceholderAttribute() : super('placeholder', AttributeScope.INLINE, true);
}
class HeaderAttribute extends Attribute<int> {
HeaderAttribute({int level}) : super('header', AttributeScope.BLOCK, level);
}

@ -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<QuillEditor>
widget.scrollable,
widget.padding,
widget.readOnly,
widget.placeholder,
widget.onLaunchUrl,
ToolbarOptions(
copy: true,

@ -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<String> 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);
}

@ -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<Attribute, TextStyle> m = {
Attribute.h1: defaultStyles.h1.style,

Loading…
Cancel
Save