fix: refactor text alignment handling in block components
This commit is contained in:
parent
e59b36173f
commit
a912c1c965
11 changed files with 28 additions and 2 deletions
|
|
@ -203,7 +203,7 @@
|
|||
isa = PBXProject;
|
||||
attributes = {
|
||||
LastSwiftUpdateCheck = 0920;
|
||||
LastUpgradeCheck = 1430;
|
||||
LastUpgradeCheck = 1300;
|
||||
ORGANIZATIONNAME = "";
|
||||
TargetAttributes = {
|
||||
33CC10EC2044A3C60003C045 = {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Scheme
|
||||
LastUpgradeVersion = "1430"
|
||||
LastUpgradeVersion = "1300"
|
||||
version = "1.3">
|
||||
<BuildAction
|
||||
parallelizeBuildables = "YES"
|
||||
|
|
|
|||
|
|
@ -136,6 +136,7 @@ class _BulletedListBlockComponentWidgetState
|
|||
key: forwardKey,
|
||||
node: widget.node,
|
||||
editorState: editorState,
|
||||
textAlign: alignment?.toTextAlign,
|
||||
placeholderText: placeholderText,
|
||||
textSpanDecorator: (textSpan) => textSpan.updateTextStyle(
|
||||
textStyle,
|
||||
|
|
|
|||
|
|
@ -142,6 +142,7 @@ class _HeadingBlockComponentWidgetState
|
|||
key: forwardKey,
|
||||
node: widget.node,
|
||||
editorState: editorState,
|
||||
textAlign: alignment?.toTextAlign,
|
||||
textSpanDecorator: (textSpan) =>
|
||||
textSpan.updateTextStyle(textStyle).updateTextStyle(
|
||||
widget.textStyleBuilder?.call(level) ??
|
||||
|
|
|
|||
|
|
@ -142,6 +142,7 @@ class _NumberedListBlockComponentWidgetState
|
|||
key: forwardKey,
|
||||
node: widget.node,
|
||||
editorState: editorState,
|
||||
textAlign: alignment?.toTextAlign,
|
||||
placeholderText: placeholderText,
|
||||
textSpanDecorator: (textSpan) => textSpan.updateTextStyle(
|
||||
textStyle,
|
||||
|
|
|
|||
|
|
@ -133,6 +133,7 @@ class _QuoteBlockComponentWidgetState extends State<QuoteBlockComponentWidget>
|
|||
key: forwardKey,
|
||||
node: widget.node,
|
||||
editorState: editorState,
|
||||
textAlign: alignment?.toTextAlign,
|
||||
placeholderText: placeholderText,
|
||||
textSpanDecorator: (textSpan) => textSpan.updateTextStyle(
|
||||
textStyle,
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ class AppFlowyRichText extends StatefulWidget {
|
|||
this.placeholderTextSpanDecorator,
|
||||
this.textDirection = TextDirection.ltr,
|
||||
this.textSpanDecoratorForCustomAttributes,
|
||||
this.textAlign,
|
||||
required this.node,
|
||||
required this.editorState,
|
||||
});
|
||||
|
|
@ -65,6 +66,8 @@ class AppFlowyRichText extends StatefulWidget {
|
|||
/// customize the text span for placeholder text
|
||||
final AppFlowyTextSpanDecorator? placeholderTextSpanDecorator;
|
||||
|
||||
final TextAlign? textAlign;
|
||||
|
||||
/// customize the text span for custom attributes
|
||||
///
|
||||
/// You can use this to customize the text span for custom attributes
|
||||
|
|
@ -247,6 +250,7 @@ class _AppFlowyRichTextState extends State<AppFlowyRichText>
|
|||
final textSpan = getTextSpan();
|
||||
return RichText(
|
||||
key: textKey,
|
||||
textAlign: widget.textAlign ?? TextAlign.start,
|
||||
textHeightBehavior: const TextHeightBehavior(
|
||||
applyHeightToFirstAscent: false,
|
||||
applyHeightToLastDescent: false,
|
||||
|
|
|
|||
|
|
@ -146,6 +146,7 @@ class _TextBlockComponentWidgetState extends State<TextBlockComponentWidget>
|
|||
key: forwardKey,
|
||||
node: widget.node,
|
||||
editorState: editorState,
|
||||
textAlign: alignment?.toTextAlign,
|
||||
placeholderText: _showPlaceholder ? placeholderText : ' ',
|
||||
textSpanDecorator: (textSpan) =>
|
||||
textSpan.updateTextStyle(textStyle),
|
||||
|
|
|
|||
|
|
@ -152,6 +152,7 @@ class _TodoListBlockComponentWidgetState
|
|||
key: forwardKey,
|
||||
node: widget.node,
|
||||
editorState: editorState,
|
||||
textAlign: alignment?.toTextAlign,
|
||||
placeholderText: placeholderText,
|
||||
textDirection: textDirection,
|
||||
textSpanDecorator: (textSpan) =>
|
||||
|
|
|
|||
15
lib/src/extensions/alignment_extension.dart
Normal file
15
lib/src/extensions/alignment_extension.dart
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
extension AppFlowyTextAlign on Alignment {
|
||||
TextAlign get toTextAlign {
|
||||
switch (this) {
|
||||
case Alignment.center:
|
||||
return TextAlign.center;
|
||||
case Alignment.centerRight:
|
||||
return TextAlign.right;
|
||||
case Alignment.centerLeft:
|
||||
default:
|
||||
return TextAlign.left;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
export 'alignment_extension.dart';
|
||||
export 'attributes_extension.dart';
|
||||
export 'color_extension.dart';
|
||||
export 'node_extensions.dart';
|
||||
|
|
|
|||
Loading…
Reference in a new issue