Fix the second issue of #1480

pull/1602/head
Ellet 1 year ago
parent cb510267e8
commit 34b73d1012
No known key found for this signature in database
GPG Key ID: C488CC70BBCEF0D1
  1. 1
      CHANGELOG.md
  2. 31
      lib/src/utils/font.dart
  3. 22
      lib/src/widgets/quill/text_block.dart
  4. 6
      lib/src/widgets/quill/text_line.dart
  5. 3
      lib/src/widgets/raw_editor/raw_editor_state_text_input_client_mixin.dart

@ -7,6 +7,7 @@ All notable changes to this project will be documented in this file.
* Add a new dropdown button by [#1575](https://github.com/singerdmx/flutter-quill/pull/1575) * Add a new dropdown button by [#1575](https://github.com/singerdmx/flutter-quill/pull/1575)
* Update the default style values by [#1575](https://github.com/singerdmx/flutter-quill/pull/1575) * Update the default style values by [#1575](https://github.com/singerdmx/flutter-quill/pull/1575)
* Fix bug [#1562](https://github.com/singerdmx/flutter-quill/issues/1562) * Fix bug [#1562](https://github.com/singerdmx/flutter-quill/issues/1562)
* Fix the second bug of [#1480](https://github.com/singerdmx/flutter-quill/issues/1480)
## 9.0.2-dev.1 ## 9.0.2-dev.1
* Add configurations for the new dropdown `QuillToolbarSelectHeaderStyleButton`, you can use the orignal one or this * Add configurations for the new dropdown `QuillToolbarSelectHeaderStyleButton`, you can use the orignal one or this

@ -1,3 +1,5 @@
import '../../flutter_quill.dart';
dynamic getFontSize(dynamic sizeValue) { dynamic getFontSize(dynamic sizeValue) {
if (sizeValue is String && if (sizeValue is String &&
['small', 'normal', 'large', 'huge'].contains(sizeValue)) { ['small', 'normal', 'large', 'huge'].contains(sizeValue)) {
@ -19,3 +21,32 @@ dynamic getFontSize(dynamic sizeValue) {
} }
return fontSize; return fontSize;
} }
double? getFontSizeAsDouble(dynamic sizeValue,
{required DefaultStyles defaultStyles}) {
if (sizeValue is String &&
['small', 'normal', 'large', 'huge'].contains(sizeValue)) {
return switch (sizeValue) {
'small' => defaultStyles.sizeSmall?.fontSize,
'normal' => null,
'large' => defaultStyles.sizeLarge?.fontSize,
'huge' => defaultStyles.sizeHuge?.fontSize,
String() => throw ArgumentError(),
};
}
if (sizeValue is double) {
return sizeValue;
}
if (sizeValue is int) {
return sizeValue.toDouble();
}
assert(sizeValue is String);
final fontSize = double.tryParse(sizeValue);
if (fontSize == null) {
throw ArgumentError('Invalid size $sizeValue');
}
return fontSize;
}

@ -7,6 +7,7 @@ import '../../models/documents/nodes/block.dart';
import '../../models/documents/nodes/line.dart'; import '../../models/documents/nodes/line.dart';
import '../../models/structs/vertical_spacing.dart'; import '../../models/structs/vertical_spacing.dart';
import '../../utils/delta.dart'; import '../../utils/delta.dart';
import '../../utils/font.dart';
import '../../utils/string.dart'; import '../../utils/string.dart';
import '../editor/editor.dart'; import '../editor/editor.dart';
import '../others/box.dart'; import '../others/box.dart';
@ -213,6 +214,7 @@ class EditableTextBlock extends StatelessWidget {
final fontSize = defaultStyles.paragraph?.style.fontSize ?? 16; final fontSize = defaultStyles.paragraph?.style.fontSize ?? 16;
final attrs = line.style.attributes; final attrs = line.style.attributes;
// Of the color button
final fontColor = final fontColor =
line.toDelta().operations.first.attributes?[Attribute.color.key] != null line.toDelta().operations.first.attributes?[Attribute.color.key] != null
? hexToColor( ? hexToColor(
@ -223,17 +225,28 @@ class EditableTextBlock extends StatelessWidget {
.attributes?[Attribute.color.key], .attributes?[Attribute.color.key],
) )
: null; : null;
// final textAlign = line.style.attributes['align']?.value != null
// ? getTextAlign(line.style.attributes['align']?.value) // Of the size button
final size =
line.toDelta().operations.first.attributes?[Attribute.size.key] != null
? getFontSizeAsDouble(
line.toDelta().operations.first.attributes?[Attribute.size.key],
defaultStyles: defaultStyles,
)
: null;
// Of the alignment buttons
// final textAlign = line.style.attributes[Attribute.align.key]?.value != null
// ? getTextAlign(line.style.attributes[Attribute.align.key]?.value)
// : null; // : null;
if (attrs[Attribute.list.key] == Attribute.ol) { if (attrs[Attribute.list.key] == Attribute.ol) {
return QuillEditorNumberPoint( return QuillEditorNumberPoint(
index: index, index: index,
// textAlign: textAlign,
indentLevelCounts: indentLevelCounts, indentLevelCounts: indentLevelCounts,
count: count, count: count,
style: defaultStyles.leading!.style.copyWith( style: defaultStyles.leading!.style.copyWith(
fontSize: size,
color: context.quillEditorElementOptions?.orderedList color: context.quillEditorElementOptions?.orderedList
.useTextColorForDot == .useTextColorForDot ==
true true
@ -250,6 +263,7 @@ class EditableTextBlock extends StatelessWidget {
return QuillEditorBulletPoint( return QuillEditorBulletPoint(
style: defaultStyles.leading!.style.copyWith( style: defaultStyles.leading!.style.copyWith(
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
fontSize: size,
color: context.quillEditorElementOptions?.unorderedList color: context.quillEditorElementOptions?.unorderedList
.useTextColorForDot == .useTextColorForDot ==
true true
@ -258,7 +272,6 @@ class EditableTextBlock extends StatelessWidget {
), ),
width: fontSize * 2, width: fontSize * 2,
padding: fontSize / 2, padding: fontSize / 2,
// textAlign: textAlign,
); );
} }
@ -284,7 +297,6 @@ class EditableTextBlock extends StatelessWidget {
attrs: attrs, attrs: attrs,
padding: fontSize, padding: fontSize,
withDot: false, withDot: false,
// textAlign: textAlign,
); );
} }
return null; return null;

@ -404,7 +404,11 @@ class _TextLineState extends State<TextLine> {
res = res.merge(defaultStyles.sizeHuge); res = res.merge(defaultStyles.sizeHuge);
break; break;
default: default:
res = res.merge(TextStyle(fontSize: getFontSize(size.value))); res = res.merge(TextStyle(
fontSize: getFontSize(
size.value,
),
));
} }
} }

@ -224,7 +224,8 @@ mixin RawEditorStateTextInputClientMixin on EditorState
widget.configurations.controller.selectedFontSize == '0' widget.configurations.controller.selectedFontSize == '0'
? null ? null
: getFontSize( : getFontSize(
widget.configurations.controller.selectedFontSize), widget.configurations.controller.selectedFontSize,
),
), ),
); );
} }

Loading…
Cancel
Save