Skip to content

Commit

Permalink
Fix the second issue of #1480
Browse files Browse the repository at this point in the history
  • Loading branch information
Ellet committed Dec 13, 2023
1 parent cb51026 commit 34b73d1
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
* 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 the second bug of [#1480](https://github.com/singerdmx/flutter-quill/issues/1480)

## 9.0.2-dev.1
* Add configurations for the new dropdown `QuillToolbarSelectHeaderStyleButton`, you can use the orignal one or this
Expand Down
31 changes: 31 additions & 0 deletions lib/src/utils/font.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import '../../flutter_quill.dart';

dynamic getFontSize(dynamic sizeValue) {
if (sizeValue is String &&
['small', 'normal', 'large', 'huge'].contains(sizeValue)) {
Expand All @@ -19,3 +21,32 @@ dynamic getFontSize(dynamic sizeValue) {
}
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;
}
22 changes: 17 additions & 5 deletions lib/src/widgets/quill/text_block.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import '../../models/documents/nodes/block.dart';
import '../../models/documents/nodes/line.dart';
import '../../models/structs/vertical_spacing.dart';
import '../../utils/delta.dart';
import '../../utils/font.dart';
import '../../utils/string.dart';
import '../editor/editor.dart';
import '../others/box.dart';
Expand Down Expand Up @@ -213,6 +214,7 @@ class EditableTextBlock extends StatelessWidget {
final fontSize = defaultStyles.paragraph?.style.fontSize ?? 16;
final attrs = line.style.attributes;

// Of the color button
final fontColor =
line.toDelta().operations.first.attributes?[Attribute.color.key] != null
? hexToColor(
Expand All @@ -223,17 +225,28 @@ class EditableTextBlock extends StatelessWidget {
.attributes?[Attribute.color.key],
)
: 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;

if (attrs[Attribute.list.key] == Attribute.ol) {
return QuillEditorNumberPoint(
index: index,
// textAlign: textAlign,
indentLevelCounts: indentLevelCounts,
count: count,
style: defaultStyles.leading!.style.copyWith(
fontSize: size,
color: context.quillEditorElementOptions?.orderedList
.useTextColorForDot ==
true
Expand All @@ -250,6 +263,7 @@ class EditableTextBlock extends StatelessWidget {
return QuillEditorBulletPoint(
style: defaultStyles.leading!.style.copyWith(
fontWeight: FontWeight.bold,
fontSize: size,
color: context.quillEditorElementOptions?.unorderedList
.useTextColorForDot ==
true
Expand All @@ -258,7 +272,6 @@ class EditableTextBlock extends StatelessWidget {
),
width: fontSize * 2,
padding: fontSize / 2,
// textAlign: textAlign,
);
}

Expand All @@ -284,7 +297,6 @@ class EditableTextBlock extends StatelessWidget {
attrs: attrs,
padding: fontSize,
withDot: false,
// textAlign: textAlign,
);
}
return null;
Expand Down
6 changes: 5 additions & 1 deletion lib/src/widgets/quill/text_line.dart
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,11 @@ class _TextLineState extends State<TextLine> {
res = res.merge(defaultStyles.sizeHuge);
break;
default:
res = res.merge(TextStyle(fontSize: getFontSize(size.value)));
res = res.merge(TextStyle(
fontSize: getFontSize(
size.value,
),
));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,8 @@ mixin RawEditorStateTextInputClientMixin on EditorState
widget.configurations.controller.selectedFontSize == '0'
? null
: getFontSize(
widget.configurations.controller.selectedFontSize),
widget.configurations.controller.selectedFontSize,
),
),
);
}
Expand Down

0 comments on commit 34b73d1

Please sign in to comment.