From e11af21fba7824e55e275952ac0c1aa500c66545 Mon Sep 17 00:00:00 2001 From: Adil Hanney Date: Thu, 1 Aug 2024 03:00:20 +0100 Subject: [PATCH] ref: add `VerticalSpacing.zero` and `HorizontalSpacing.zero` named constants (#2083) * feat: add named constants to HorizontalSpacing/VerticalSpacing * ref: use VerticalSpacing.zero across code --- .../lib/screens/quill/my_quill_editor.dart | 4 +- .../common/structs/horizontal_spacing.dart | 2 + lib/src/common/structs/vertical_spacing.dart | 2 + .../editor/raw_editor/raw_editor_state.dart | 4 +- lib/src/editor/widgets/default_styles.dart | 46 +++++++++---------- 5 files changed, 31 insertions(+), 27 deletions(-) diff --git a/example/lib/screens/quill/my_quill_editor.dart b/example/lib/screens/quill/my_quill_editor.dart index dee4691f..e4f01a82 100644 --- a/example/lib/screens/quill/my_quill_editor.dart +++ b/example/lib/screens/quill/my_quill_editor.dart @@ -54,9 +54,9 @@ class MyQuillEditor extends StatelessWidget { height: 1.15, fontWeight: FontWeight.w300, ), - const HorizontalSpacing(0, 0), + HorizontalSpacing.zero, const VerticalSpacing(16, 0), - const VerticalSpacing(0, 0), + VerticalSpacing.zero, null, ), sizeSmall: defaultTextStyle.style.copyWith(fontSize: 9), diff --git a/lib/src/common/structs/horizontal_spacing.dart b/lib/src/common/structs/horizontal_spacing.dart index 3ed47d57..a330e968 100644 --- a/lib/src/common/structs/horizontal_spacing.dart +++ b/lib/src/common/structs/horizontal_spacing.dart @@ -9,4 +9,6 @@ class HorizontalSpacing { final double left; final double right; + + static const zero = HorizontalSpacing(0, 0); } diff --git a/lib/src/common/structs/vertical_spacing.dart b/lib/src/common/structs/vertical_spacing.dart index cc8724a2..cf46ef4c 100644 --- a/lib/src/common/structs/vertical_spacing.dart +++ b/lib/src/common/structs/vertical_spacing.dart @@ -9,4 +9,6 @@ class VerticalSpacing { final double top; final double bottom; + + static const zero = VerticalSpacing(0, 0); } diff --git a/lib/src/editor/raw_editor/raw_editor_state.dart b/lib/src/editor/raw_editor/raw_editor_state.dart index 0525a6f1..b810147f 100644 --- a/lib/src/editor/raw_editor/raw_editor_state.dart +++ b/lib/src/editor/raw_editor/raw_editor_state.dart @@ -1145,7 +1145,7 @@ class QuillRawEditorState extends EditorState } else if (attrs.containsKey(Attribute.align.key)) { return defaultStyles!.align!.horizontalSpacing; } - return const HorizontalSpacing(0, 0); + return HorizontalSpacing.zero; } VerticalSpacing _getVerticalSpacingForBlock( @@ -1162,7 +1162,7 @@ class QuillRawEditorState extends EditorState } else if (attrs.containsKey(Attribute.align.key)) { return defaultStyles!.align!.verticalSpacing; } - return const VerticalSpacing(0, 0); + return VerticalSpacing.zero; } void _didChangeTextEditingValueListener() { diff --git a/lib/src/editor/widgets/default_styles.dart b/lib/src/editor/widgets/default_styles.dart index da6e0f8a..c7bcb65d 100644 --- a/lib/src/editor/widgets/default_styles.dart +++ b/lib/src/editor/widgets/default_styles.dart @@ -271,7 +271,7 @@ class DefaultStyles { ), baseHorizontalSpacing, const VerticalSpacing(16, 0), - const VerticalSpacing(0, 0), + VerticalSpacing.zero, null), h2: DefaultTextBlockStyle( defaultTextStyle.style.copyWith( @@ -284,7 +284,7 @@ class DefaultStyles { ), baseHorizontalSpacing, const VerticalSpacing(8, 0), - const VerticalSpacing(0, 0), + VerticalSpacing.zero, null), h3: DefaultTextBlockStyle( defaultTextStyle.style.copyWith( @@ -297,7 +297,7 @@ class DefaultStyles { ), baseHorizontalSpacing, const VerticalSpacing(8, 0), - const VerticalSpacing(0, 0), + VerticalSpacing.zero, null, ), h4: DefaultTextBlockStyle( @@ -311,7 +311,7 @@ class DefaultStyles { ), baseHorizontalSpacing, const VerticalSpacing(6, 0), - const VerticalSpacing(0, 0), + VerticalSpacing.zero, null, ), h5: DefaultTextBlockStyle( @@ -325,7 +325,7 @@ class DefaultStyles { ), baseHorizontalSpacing, const VerticalSpacing(6, 0), - const VerticalSpacing(0, 0), + VerticalSpacing.zero, null, ), h6: DefaultTextBlockStyle( @@ -339,42 +339,42 @@ class DefaultStyles { ), baseHorizontalSpacing, const VerticalSpacing(4, 0), - const VerticalSpacing(0, 0), + VerticalSpacing.zero, null, ), lineHeightNormal: DefaultTextBlockStyle( baseStyle.copyWith(height: 1.15), baseHorizontalSpacing, - const VerticalSpacing(0, 0), - const VerticalSpacing(0, 0), + VerticalSpacing.zero, + VerticalSpacing.zero, null, ), lineHeightTight: DefaultTextBlockStyle( baseStyle.copyWith(height: 1.30), baseHorizontalSpacing, - const VerticalSpacing(0, 0), - const VerticalSpacing(0, 0), + VerticalSpacing.zero, + VerticalSpacing.zero, null, ), lineHeightOneAndHalf: DefaultTextBlockStyle( baseStyle.copyWith(height: 1.55), baseHorizontalSpacing, - const VerticalSpacing(0, 0), - const VerticalSpacing(0, 0), + VerticalSpacing.zero, + VerticalSpacing.zero, null, ), lineHeightDouble: DefaultTextBlockStyle( baseStyle.copyWith(height: 2), baseHorizontalSpacing, - const VerticalSpacing(0, 0), - const VerticalSpacing(0, 0), + VerticalSpacing.zero, + VerticalSpacing.zero, null, ), paragraph: DefaultTextBlockStyle( baseStyle, baseHorizontalSpacing, - const VerticalSpacing(0, 0), - const VerticalSpacing(0, 0), + VerticalSpacing.zero, + VerticalSpacing.zero, null, ), bold: const TextStyle(fontWeight: FontWeight.bold), @@ -422,8 +422,8 @@ class DefaultStyles { color: Colors.grey.withOpacity(0.6), ), baseHorizontalSpacing, - const VerticalSpacing(0, 0), - const VerticalSpacing(0, 0), + VerticalSpacing.zero, + VerticalSpacing.zero, null), lists: DefaultListBlockStyle( baseStyle, @@ -453,7 +453,7 @@ class DefaultStyles { ), baseHorizontalSpacing, baseVerticalSpacing, - const VerticalSpacing(0, 0), + VerticalSpacing.zero, BoxDecoration( color: Colors.grey.shade50, borderRadius: BorderRadius.circular(2), @@ -468,15 +468,15 @@ class DefaultStyles { align: DefaultTextBlockStyle( baseStyle, baseHorizontalSpacing, - const VerticalSpacing(0, 0), - const VerticalSpacing(0, 0), + VerticalSpacing.zero, + VerticalSpacing.zero, null, ), leading: DefaultTextBlockStyle( baseStyle, baseHorizontalSpacing, - const VerticalSpacing(0, 0), - const VerticalSpacing(0, 0), + VerticalSpacing.zero, + VerticalSpacing.zero, null, ), sizeSmall: const TextStyle(fontSize: 10),