support for custom styling property and height calculation bug cleared

pull/31/head
ritheshSalyan 4 years ago
parent 87ab79c8fd
commit 14b38b6701
  1. 5
      app/lib/widgets/field.dart
  2. 3
      lib/widgets/delegate.dart
  3. 8
      lib/widgets/editor.dart
  4. 5
      lib/widgets/raw_editor.dart
  5. 38
      lib/widgets/text_line.dart

@ -24,7 +24,7 @@ class QuillField extends StatefulWidget {
final InputDecoration decoration; final InputDecoration decoration;
final Widget toolbar; final Widget toolbar;
final EmbedBuilder embedBuilder; final EmbedBuilder embedBuilder;
final StyleBuilder styleBuilder;
QuillField({ QuillField({
Key key, Key key,
@required this.controller, @required this.controller,
@ -45,7 +45,7 @@ class QuillField extends StatefulWidget {
this.onLaunchUrl, this.onLaunchUrl,
this.decoration, this.decoration,
this.toolbar, this.toolbar,
this.embedBuilder, this.embedBuilder, this.styleBuilder,
}) : super(key: key); }) : super(key: key);
@override @override
@ -98,6 +98,7 @@ class _QuillFieldState extends State<QuillField> {
scrollPhysics: widget.scrollPhysics, scrollPhysics: widget.scrollPhysics,
onLaunchUrl: widget.onLaunchUrl, onLaunchUrl: widget.onLaunchUrl,
embedBuilder: widget.embedBuilder, embedBuilder: widget.embedBuilder,
styleBuilder:widget.styleBuilder,
); );
if (widget.toolbar != null) { if (widget.toolbar != null) {

@ -3,12 +3,13 @@ import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart'; import 'package:flutter/rendering.dart';
import 'package:flutter_quill/models/documents/nodes/leaf.dart'; import 'package:flutter_quill/models/documents/nodes/leaf.dart';
import 'package:flutter_quill/models/documents/attribute.dart';
import 'package:flutter_quill/widgets/text_selection.dart'; import 'package:flutter_quill/widgets/text_selection.dart';
import 'editor.dart'; import 'editor.dart';
typedef EmbedBuilder = Widget Function(BuildContext context, Embed node); typedef EmbedBuilder = Widget Function(BuildContext context, Embed node);
typedef StyleBuilder = TextStyle Function(Attribute<dynamic> attribute);
abstract class EditorTextSelectionGestureDetectorBuilderDelegate { abstract class EditorTextSelectionGestureDetectorBuilderDelegate {
GlobalKey<EditorState> getEditableTextKey(); GlobalKey<EditorState> getEditableTextKey();

@ -144,7 +144,7 @@ class QuillEditor extends StatefulWidget {
final ScrollPhysics scrollPhysics; final ScrollPhysics scrollPhysics;
final ValueChanged<String> onLaunchUrl; final ValueChanged<String> onLaunchUrl;
final EmbedBuilder embedBuilder; final EmbedBuilder embedBuilder;
final StyleBuilder styleBuilder;
QuillEditor( QuillEditor(
{@required this.controller, {@required this.controller,
@required this.focusNode, @required this.focusNode,
@ -164,7 +164,7 @@ class QuillEditor extends StatefulWidget {
this.scrollPhysics, this.scrollPhysics,
this.onLaunchUrl, this.onLaunchUrl,
this.embedBuilder = this.embedBuilder =
kIsWeb ? _defaultEmbedBuilderWeb : _defaultEmbedBuilder}) kIsWeb ? _defaultEmbedBuilderWeb : _defaultEmbedBuilder, this.styleBuilder})
: assert(controller != null), : assert(controller != null),
assert(scrollController != null), assert(scrollController != null),
assert(scrollable != null), assert(scrollable != null),
@ -286,7 +286,9 @@ class _QuillEditorState extends State<QuillEditor>
widget.keyboardAppearance, widget.keyboardAppearance,
widget.enableInteractiveSelection, widget.enableInteractiveSelection,
widget.scrollPhysics, widget.scrollPhysics,
widget.embedBuilder), widget.embedBuilder,
widget.styleBuilder,
),
); );
} }

@ -49,7 +49,7 @@ class RawEditor extends StatefulWidget {
final bool enableInteractiveSelection; final bool enableInteractiveSelection;
final ScrollPhysics scrollPhysics; final ScrollPhysics scrollPhysics;
final EmbedBuilder embedBuilder; final EmbedBuilder embedBuilder;
final StyleBuilder styleBuilder;
RawEditor( RawEditor(
Key key, Key key,
this.controller, this.controller,
@ -74,7 +74,7 @@ class RawEditor extends StatefulWidget {
this.keyboardAppearance, this.keyboardAppearance,
this.enableInteractiveSelection, this.enableInteractiveSelection,
this.scrollPhysics, this.scrollPhysics,
this.embedBuilder) this.embedBuilder, this.styleBuilder)
: assert(controller != null, 'controller cannot be null'), : assert(controller != null, 'controller cannot be null'),
assert(focusNode != null, 'focusNode cannot be null'), assert(focusNode != null, 'focusNode cannot be null'),
assert(scrollable || scrollController != null, assert(scrollable || scrollController != null,
@ -571,6 +571,7 @@ class RawEditorState extends EditorState
line: node, line: node,
textDirection: _textDirection, textDirection: _textDirection,
embedBuilder: widget.embedBuilder, embedBuilder: widget.embedBuilder,
styleBuilder:widget.styleBuilder,
styles: _styles, styles: _styles,
); );
EditableTextLine editableTextLine = EditableTextLine( EditableTextLine editableTextLine = EditableTextLine(

@ -25,10 +25,16 @@ class TextLine extends StatelessWidget {
final Line line; final Line line;
final TextDirection textDirection; final TextDirection textDirection;
final EmbedBuilder embedBuilder; final EmbedBuilder embedBuilder;
final StyleBuilder styleBuilder;
final DefaultStyles styles; final DefaultStyles styles;
const TextLine( const TextLine(
{Key key, this.line, this.textDirection, this.embedBuilder, this.styles}) {Key key,
this.line,
this.textDirection,
this.embedBuilder,
this.styles,
this.styleBuilder})
: assert(line != null), : assert(line != null),
assert(embedBuilder != null), assert(embedBuilder != null),
assert(styles != null), assert(styles != null),
@ -43,12 +49,12 @@ class TextLine extends StatelessWidget {
return EmbedProxy(embedBuilder(context, embed)); return EmbedProxy(embedBuilder(context, embed));
} }
TextSpan textSpan = _buildTextSpan(context); TextSpan textSpan = _buildTextSpan(context, styleBuilder);
StrutStyle strutStyle = StrutStyle strutStyle =
StrutStyle.fromTextStyle(textSpan.style, forceStrutHeight: true); StrutStyle.fromTextStyle(textSpan.style, forceStrutHeight: true);
final textAlign = _getTextAlign(); final textAlign = _getTextAlign();
RichText child = RichText( RichText child = RichText(
text: _buildTextSpan(context), text: TextSpan(children: [_buildTextSpan(context,styleBuilder)]),
textAlign: textAlign, textAlign: textAlign,
textDirection: textDirection, textDirection: textDirection,
strutStyle: strutStyle, strutStyle: strutStyle,
@ -80,10 +86,10 @@ class TextLine extends StatelessWidget {
return TextAlign.start; return TextAlign.start;
} }
TextSpan _buildTextSpan(BuildContext context) { TextSpan _buildTextSpan(BuildContext context, StyleBuilder styleBuilder) {
DefaultStyles defaultStyles = styles; DefaultStyles defaultStyles = styles;
List<TextSpan> children = line.children List<TextSpan> children = line.children
.map((node) => _getTextSpanFromNode(defaultStyles, node)) .map((node) => _getTextSpanFromNode(defaultStyles, node, styleBuilder))
.toList(growable: false); .toList(growable: false);
TextStyle textStyle = TextStyle(); TextStyle textStyle = TextStyle();
@ -112,7 +118,8 @@ class TextLine extends StatelessWidget {
return TextSpan(children: children, style: textStyle); return TextSpan(children: children, style: textStyle);
} }
TextSpan _getTextSpanFromNode(DefaultStyles defaultStyles, Node node) { TextSpan _getTextSpanFromNode(
DefaultStyles defaultStyles, Node node, StyleBuilder styleBuilder) {
leaf.Text textNode = node as leaf.Text; leaf.Text textNode = node as leaf.Text;
Style style = textNode.style; Style style = textNode.style;
TextStyle res = TextStyle(); TextStyle res = TextStyle();
@ -137,7 +144,6 @@ class TextLine extends StatelessWidget {
Attribute size = textNode.style.attributes[Attribute.size.key]; Attribute size = textNode.style.attributes[Attribute.size.key];
if (size != null && size.value != null) { if (size != null && size.value != null) {
switch (size.value) { switch (size.value) {
case 'small': case 'small':
res = res.merge(defaultStyles.sizeSmall); res = res.merge(defaultStyles.sizeSmall);
@ -150,11 +156,10 @@ class TextLine extends StatelessWidget {
break; break;
default: default:
double fontSize = double.tryParse(size.value); double fontSize = double.tryParse(size.value);
if(fontSize!=null){ if (fontSize != null) {
res = res.merge(TextStyle(fontSize: fontSize)); res = res.merge(TextStyle(fontSize: fontSize));
} } else
else throw "Invalid size ${size.value}";
throw "Invalid size ${size.value}";
} }
} }
@ -169,7 +174,16 @@ class TextLine extends StatelessWidget {
final backgroundColor = stringToColor(background.value); final backgroundColor = stringToColor(background.value);
res = res.merge(new TextStyle(backgroundColor: backgroundColor)); res = res.merge(new TextStyle(backgroundColor: backgroundColor));
} }
if (styleBuilder != null)
textNode.style.attributes.keys.forEach((key) {
Attribute attribute =
Attribute.fromKeyValue(key, textNode.style.attributes[key]);
if (attribute == null) {
///Unkown Attribute
TextStyle customStyle = styleBuilder( textNode.style.attributes[key]);
if (customStyle != null) res = res.merge(customStyle);
}
});
return TextSpan(text: textNode.value, style: res); return TextSpan(text: textNode.value, style: res);
} }

Loading…
Cancel
Save