support custom width for text bolck

pull/350/head
ritheshSalyan 4 years ago
parent 14b38b6701
commit c3329662c9
  1. 1
      lib/flutter_quill.dart
  2. 18
      lib/widgets/default_styles.dart
  3. 4
      lib/widgets/raw_editor.dart
  4. 16
      lib/widgets/text_block.dart

@ -1 +1,2 @@
library flutter_quill;
export 'package:tuple/tuple.dart';

@ -59,9 +59,9 @@ class DefaultStyles {
final DefaultTextBlockStyle code;
final DefaultTextBlockStyle indent;
final DefaultTextBlockStyle align;
DefaultStyles(
{this.h1,
final DefaultTextBlockStyle textBlockStyle;
DefaultStyles({
this.h1,
this.h2,
this.h3,
this.paragraph,
@ -77,7 +77,9 @@ class DefaultStyles {
this.align,
this.sizeSmall,
this.sizeLarge,
this.sizeHuge});
this.sizeHuge,
this.textBlockStyle,
});
static DefaultStyles getInstance(BuildContext context) {
ThemeData themeData = Theme.of(context);
@ -174,7 +176,9 @@ class DefaultStyles {
baseStyle, Tuple2(0.0, 0.0), Tuple2(0.0, 0.0), null),
sizeSmall: TextStyle(fontSize: 10.0),
sizeLarge: TextStyle(fontSize: 18.0),
sizeHuge: TextStyle(fontSize: 22.0));
sizeHuge: TextStyle(fontSize: 22.0),
textBlockStyle: DefaultTextBlockStyle(baseStyle, Tuple2(0.0, 0.0), Tuple2(32.0, 0.0), null)
);
}
DefaultStyles merge(DefaultStyles other) {
@ -195,6 +199,8 @@ class DefaultStyles {
align: other.align ?? this.align,
sizeSmall: other.sizeSmall ?? this.sizeSmall,
sizeLarge: other.sizeLarge ?? this.sizeLarge,
sizeHuge: other.sizeHuge ?? this.sizeHuge);
sizeHuge: other.sizeHuge ?? this.sizeHuge,
textBlockStyle: other.textBlockStyle??this.textBlockStyle,
);
}
}

@ -604,7 +604,9 @@ class RawEditorState extends EditorState
: null,
widget.embedBuilder,
_cursorCont,
indentLevelCounts);
indentLevelCounts,
widget.styleBuilder,
);
result.add(editableTextBlock);
} else {
throw StateError('Unreachable.');

@ -58,6 +58,7 @@ class EditableTextBlock extends StatelessWidget {
final bool hasFocus;
final EdgeInsets contentPadding;
final EmbedBuilder embedBuilder;
final StyleBuilder styleBuilder;
final CursorCont cursorCont;
final Map<int, int> indentLevelCounts;
@ -73,7 +74,7 @@ class EditableTextBlock extends StatelessWidget {
this.contentPadding,
this.embedBuilder,
this.cursorCont,
this.indentLevelCounts)
this.indentLevelCounts, this.styleBuilder)
: assert(hasFocus != null),
assert(embedBuilder != null),
assert(cursorCont != null);
@ -114,14 +115,15 @@ class EditableTextBlock extends StatelessWidget {
index++;
EditableTextLine editableTextLine = EditableTextLine(
line,
_buildLeading(context, line, index, indentLevelCounts, count),
Center(child: _buildLeading(context, line, index, indentLevelCounts, count)),
TextLine(
line: line,
textDirection: textDirection,
embedBuilder: embedBuilder,
styleBuilder:styleBuilder,
styles: styles,
),
_getIndentWidth(),
_getIndentWidth(defaultStyles),
_getSpacingForLine(line, index, count, defaultStyles),
textDirection,
textSelection,
@ -185,9 +187,9 @@ class EditableTextBlock extends StatelessWidget {
return null;
}
double _getIndentWidth() {
double _getIndentWidth(DefaultStyles defaultStyles) {
Map<String, Attribute> attrs = block.style.attributes;
double minimumIndent = defaultStyles?.textBlockStyle?.lineSpacing?.item1??0;
Attribute indent = attrs[Attribute.indent.key];
double extraIndent = 0.0;
if (indent != null && indent.value != null) {
@ -195,10 +197,10 @@ class EditableTextBlock extends StatelessWidget {
}
if (attrs.containsKey(Attribute.blockQuote.key)) {
return 16.0 + extraIndent;
return minimumIndent + extraIndent;
}
return 32.0 + extraIndent;
return minimumIndent + extraIndent;
}
Tuple2 _getSpacingForLine(

Loading…
Cancel
Save