chore: dart fixes

pull/1972/head
CatHood0 10 months ago
parent 5aece8d529
commit 99ec1a7b04
  1. 9
      lib/src/models/config/toolbar/buttons/select_line_height_style_dropdown_button_configurations.dart
  2. 61
      lib/src/models/documents/attribute.dart
  3. 3
      lib/src/widgets/quill/text_line.dart
  4. 27
      lib/src/widgets/toolbar/buttons/select_line_height_dropdown_button.dart
  5. 1
      lib/src/widgets/toolbar/simple_toolbar.dart

@ -1,10 +1,12 @@
import 'package:flutter/widgets.dart' show IconData, TextStyle, ValueChanged, VoidCallback; import 'package:flutter/widgets.dart'
show IconData, TextStyle, ValueChanged, VoidCallback;
import '../../../../widgets/toolbar/base_toolbar.dart'; import '../../../../widgets/toolbar/base_toolbar.dart';
import '../../../documents/attribute.dart'; import '../../../documents/attribute.dart';
import '../../../themes/quill_icon_theme.dart'; import '../../../themes/quill_icon_theme.dart';
class QuillToolbarSelectLineHeightStyleDropdownButtonExtraOptions extends QuillToolbarBaseButtonExtraOptions { class QuillToolbarSelectLineHeightStyleDropdownButtonExtraOptions
extends QuillToolbarBaseButtonExtraOptions {
const QuillToolbarSelectLineHeightStyleDropdownButtonExtraOptions({ const QuillToolbarSelectLineHeightStyleDropdownButtonExtraOptions({
required super.controller, required super.controller,
required super.context, required super.context,
@ -14,7 +16,8 @@ class QuillToolbarSelectLineHeightStyleDropdownButtonExtraOptions extends QuillT
final Attribute currentValue; final Attribute currentValue;
} }
class QuillToolbarSelectLineHeightStyleDropdownButtonOptions extends QuillToolbarBaseButtonOptions< class QuillToolbarSelectLineHeightStyleDropdownButtonOptions
extends QuillToolbarBaseButtonOptions<
QuillToolbarSelectLineHeightStyleDropdownButtonOptions, QuillToolbarSelectLineHeightStyleDropdownButtonOptions,
QuillToolbarSelectLineHeightStyleDropdownButtonExtraOptions> { QuillToolbarSelectLineHeightStyleDropdownButtonExtraOptions> {
const QuillToolbarSelectLineHeightStyleDropdownButtonOptions({ const QuillToolbarSelectLineHeightStyleDropdownButtonOptions({

@ -58,9 +58,11 @@ class Attribute<T> extends Equatable {
static const BoldAttribute bold = BoldAttribute(); static const BoldAttribute bold = BoldAttribute();
static final ScriptAttribute subscript = ScriptAttribute(ScriptAttributes.sub); static final ScriptAttribute subscript =
ScriptAttribute(ScriptAttributes.sub);
static final ScriptAttribute superscript = ScriptAttribute(ScriptAttributes.sup); static final ScriptAttribute superscript =
ScriptAttribute(ScriptAttributes.sup);
static const ItalicAttribute italic = ItalicAttribute(); static const ItalicAttribute italic = ItalicAttribute();
@ -180,16 +182,20 @@ class Attribute<T> extends Equatable {
static const Attribute<int?> h6 = HeaderAttribute(level: 6); static const Attribute<int?> h6 = HeaderAttribute(level: 6);
/// "attributes":{"line-height": 1.0 } /// "attributes":{"line-height": 1.0 }
static const Attribute<double?> lineHeightNormal = LineHeightAttribute(lineHeight: 1); static const Attribute<double?> lineHeightNormal =
LineHeightAttribute(lineHeight: 1);
/// "attributes":{"line-height": 1.15 } /// "attributes":{"line-height": 1.15 }
static const Attribute<double?> lineHeightTight = LineHeightAttribute(lineHeight: 1.15); static const Attribute<double?> lineHeightTight =
LineHeightAttribute(lineHeight: 1.15);
/// "attributes":{"line-height": 1.5 } /// "attributes":{"line-height": 1.5 }
static const Attribute<double?> lineHeightOneAndHalf = LineHeightAttribute(lineHeight: 1.5); static const Attribute<double?> lineHeightOneAndHalf =
LineHeightAttribute(lineHeight: 1.5);
/// "attributes":{"line-height": 2.0 } /// "attributes":{"line-height": 2.0 }
static const Attribute<double?> lineHeightDouble = LineHeightAttribute(lineHeight: 2); static const Attribute<double?> lineHeightDouble =
LineHeightAttribute(lineHeight: 2);
// "attributes":{"align":"left"} // "attributes":{"align":"left"}
static const Attribute<String?> leftAlignment = AlignAttribute('left'); static const Attribute<String?> leftAlignment = AlignAttribute('left');
@ -277,7 +283,9 @@ class Attribute<T> extends Equatable {
if (identical(this, other)) return true; if (identical(this, other)) return true;
if (other is! Attribute) return false; if (other is! Attribute) return false;
final typedOther = other; final typedOther = other;
return key == typedOther.key && scope == typedOther.scope && value == typedOther.value; return key == typedOther.key &&
scope == typedOther.scope &&
value == typedOther.value;
} }
// This might not needed anymore because of equatable // This might not needed anymore because of equatable
@ -330,28 +338,34 @@ class LinkAttribute extends Attribute<String?> {
} }
class ColorAttribute extends Attribute<String?> { class ColorAttribute extends Attribute<String?> {
const ColorAttribute(String? val) : super('color', AttributeScope.inline, val); const ColorAttribute(String? val)
: super('color', AttributeScope.inline, val);
} }
class BackgroundAttribute extends Attribute<String?> { class BackgroundAttribute extends Attribute<String?> {
const BackgroundAttribute(String? val) : super('background', AttributeScope.inline, val); const BackgroundAttribute(String? val)
: super('background', AttributeScope.inline, val);
} }
/// This is custom attribute for hint /// This is custom attribute for hint
class PlaceholderAttribute extends Attribute<bool> { class PlaceholderAttribute extends Attribute<bool> {
const PlaceholderAttribute() : super('placeholder', AttributeScope.inline, true); const PlaceholderAttribute()
: super('placeholder', AttributeScope.inline, true);
} }
class HeaderAttribute extends Attribute<int?> { class HeaderAttribute extends Attribute<int?> {
const HeaderAttribute({int? level}) : super('header', AttributeScope.block, level); const HeaderAttribute({int? level})
: super('header', AttributeScope.block, level);
} }
class LineHeightAttribute extends Attribute<double?> { class LineHeightAttribute extends Attribute<double?> {
const LineHeightAttribute({double? lineHeight}) : super('line-height', AttributeScope.block, lineHeight); const LineHeightAttribute({double? lineHeight})
: super('line-height', AttributeScope.block, lineHeight);
} }
class IndentAttribute extends Attribute<int?> { class IndentAttribute extends Attribute<int?> {
const IndentAttribute({int? level}) : super('indent', AttributeScope.block, level); const IndentAttribute({int? level})
: super('indent', AttributeScope.block, level);
} }
class AlignAttribute extends Attribute<String?> { class AlignAttribute extends Attribute<String?> {
@ -371,19 +385,23 @@ class BlockQuoteAttribute extends Attribute<bool> {
} }
class DirectionAttribute extends Attribute<String?> { class DirectionAttribute extends Attribute<String?> {
const DirectionAttribute(String? val) : super('direction', AttributeScope.block, val); const DirectionAttribute(String? val)
: super('direction', AttributeScope.block, val);
} }
class WidthAttribute extends Attribute<String?> { class WidthAttribute extends Attribute<String?> {
const WidthAttribute(String? val) : super('width', AttributeScope.ignore, val); const WidthAttribute(String? val)
: super('width', AttributeScope.ignore, val);
} }
class HeightAttribute extends Attribute<String?> { class HeightAttribute extends Attribute<String?> {
const HeightAttribute(String? val) : super('height', AttributeScope.ignore, val); const HeightAttribute(String? val)
: super('height', AttributeScope.ignore, val);
} }
class StyleAttribute extends Attribute<String?> { class StyleAttribute extends Attribute<String?> {
const StyleAttribute(String? val) : super('style', AttributeScope.ignore, val); const StyleAttribute(String? val)
: super('style', AttributeScope.ignore, val);
} }
class TokenAttribute extends Attribute<String> { class TokenAttribute extends Attribute<String> {
@ -391,7 +409,8 @@ class TokenAttribute extends Attribute<String> {
} }
class ScriptAttribute extends Attribute<String?> { class ScriptAttribute extends Attribute<String?> {
ScriptAttribute(ScriptAttributes? val) : super('script', AttributeScope.inline, val?.value); ScriptAttribute(ScriptAttributes? val)
: super('script', AttributeScope.inline, val?.value);
} }
enum ScriptAttributes { enum ScriptAttributes {
@ -404,9 +423,11 @@ enum ScriptAttributes {
} }
class ImageAttribute extends Attribute<String?> { class ImageAttribute extends Attribute<String?> {
const ImageAttribute(String? url) : super('image', AttributeScope.embeds, url); const ImageAttribute(String? url)
: super('image', AttributeScope.embeds, url);
} }
class VideoAttribute extends Attribute<String?> { class VideoAttribute extends Attribute<String?> {
const VideoAttribute(String? url) : super('video', AttributeScope.embeds, url); const VideoAttribute(String? url)
: super('video', AttributeScope.embeds, url);
} }

@ -310,7 +310,8 @@ class _TextLineState extends State<TextLine> {
Attribute.lineHeightDouble: defaultStyles.lineHeightDouble!.style, Attribute.lineHeightDouble: defaultStyles.lineHeightDouble!.style,
}; };
textStyle = textStyle.merge(textStyle.copyWith(height: x[lineHeight]?.height)); textStyle =
textStyle.merge(textStyle.copyWith(height: x[lineHeight]?.height));
textStyle = _applyCustomAttributes(textStyle, widget.line.style.attributes); textStyle = _applyCustomAttributes(textStyle, widget.line.style.attributes);

@ -7,19 +7,24 @@ import '../../../models/documents/attribute.dart';
import '../base_button/base_value_button.dart'; import '../base_button/base_value_button.dart';
import '../base_toolbar.dart'; import '../base_toolbar.dart';
typedef QuillToolbarSelectLineHeightStyleDropdownBaseButton = QuillToolbarBaseButton< typedef QuillToolbarSelectLineHeightStyleDropdownBaseButton
= QuillToolbarBaseButton<
QuillToolbarSelectLineHeightStyleDropdownButtonOptions, QuillToolbarSelectLineHeightStyleDropdownButtonOptions,
QuillToolbarSelectLineHeightStyleDropdownButtonExtraOptions>; QuillToolbarSelectLineHeightStyleDropdownButtonExtraOptions>;
typedef QuillToolbarSelectLineHeightStyleDropdownBaseButtonsState< typedef QuillToolbarSelectLineHeightStyleDropdownBaseButtonsState<
W extends QuillToolbarSelectLineHeightStyleDropdownButton> W extends QuillToolbarSelectLineHeightStyleDropdownButton>
= QuillToolbarCommonButtonState<W, QuillToolbarSelectLineHeightStyleDropdownButtonOptions, = QuillToolbarCommonButtonState<
W,
QuillToolbarSelectLineHeightStyleDropdownButtonOptions,
QuillToolbarSelectLineHeightStyleDropdownButtonExtraOptions>; QuillToolbarSelectLineHeightStyleDropdownButtonExtraOptions>;
class QuillToolbarSelectLineHeightStyleDropdownButton extends QuillToolbarSelectLineHeightStyleDropdownBaseButton { class QuillToolbarSelectLineHeightStyleDropdownButton
extends QuillToolbarSelectLineHeightStyleDropdownBaseButton {
const QuillToolbarSelectLineHeightStyleDropdownButton({ const QuillToolbarSelectLineHeightStyleDropdownButton({
required super.controller, required super.controller,
super.options = const QuillToolbarSelectLineHeightStyleDropdownButtonOptions(), super.options =
const QuillToolbarSelectLineHeightStyleDropdownButtonOptions(),
super.key, super.key,
}); });
@ -52,7 +57,8 @@ class _QuillToolbarSelectLineHeightStyleDropdownButtonState
} }
@override @override
void didUpdateWidget(covariant QuillToolbarSelectLineHeightStyleDropdownButton oldWidget) { void didUpdateWidget(
covariant QuillToolbarSelectLineHeightStyleDropdownButton oldWidget) {
super.didUpdateWidget(oldWidget); super.didUpdateWidget(oldWidget);
if (oldWidget.controller == widget.controller) { if (oldWidget.controller == widget.controller) {
return; return;
@ -73,12 +79,16 @@ class _QuillToolbarSelectLineHeightStyleDropdownButtonState
} }
Attribute<dynamic> _getLineHeightValue() { Attribute<dynamic> _getLineHeightValue() {
final attr = widget.controller.toolbarButtonToggler[Attribute.lineHeight.key]; final attr =
widget.controller.toolbarButtonToggler[Attribute.lineHeight.key];
if (attr != null) { if (attr != null) {
widget.controller.toolbarButtonToggler.remove(Attribute.lineHeight.key); widget.controller.toolbarButtonToggler.remove(Attribute.lineHeight.key);
return attr; return attr;
} }
return widget.controller.getSelectionStyle().attributes[Attribute.lineHeight.key] ?? Attribute.lineHeight; return widget.controller
.getSelectionStyle()
.attributes[Attribute.lineHeight.key] ??
Attribute.lineHeight;
} }
String _label(Attribute<dynamic> attribute) { String _label(Attribute<dynamic> attribute) {
@ -107,7 +117,8 @@ class _QuillToolbarSelectLineHeightStyleDropdownButtonState
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final baseButtonConfigurations = context.quillToolbarBaseButtonOptions; final baseButtonConfigurations = context.quillToolbarBaseButtonOptions;
final childBuilder = widget.options.childBuilder ?? baseButtonConfigurations?.childBuilder; final childBuilder =
widget.options.childBuilder ?? baseButtonConfigurations?.childBuilder;
if (childBuilder != null) { if (childBuilder != null) {
return childBuilder( return childBuilder(
widget.options, widget.options,

@ -196,7 +196,6 @@ class QuillSimpleToolbar extends StatelessWidget
isButtonGroupShown[4] || isButtonGroupShown[4] ||
isButtonGroupShown[5])) isButtonGroupShown[5]))
divider, divider,
if (configurations.showLineHeightButton) if (configurations.showLineHeightButton)
QuillToolbarSelectLineHeightStyleDropdownButton( QuillToolbarSelectLineHeightStyleDropdownButton(
controller: globalController, controller: globalController,

Loading…
Cancel
Save