Skip to content

Commit da4be28

Browse files
Add copyWith methods to DefaultStyles, HorizontalSpacing, and VerticalSpacing (#2550)
* feat: add copyWith * docs(changelog): add changes --------- Co-authored-by: Ellet <[email protected]>
1 parent cba1788 commit da4be28

File tree

5 files changed

+146
-58
lines changed

5 files changed

+146
-58
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
1111
## [Unreleased]
1212

13+
### Added
14+
15+
- `copyWith` methods to `HorizontalSpacing`, `VerticalSpacing`, `DefaultTextBlockStyle`, and `DefaultListBlockStyle` for immutable updates of properties [#2550](https://github.com/singerdmx/flutter-quill/pull/2550).
16+
1317
## [11.4.0] - 2025-04-23
1418

1519
### Added

lib/src/common/structs/horizontal_spacing.dart

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,24 @@ class HorizontalSpacing {
1111
final double right;
1212

1313
static const zero = HorizontalSpacing(0, 0);
14+
15+
HorizontalSpacing copyWith({
16+
double? left,
17+
double? right,
18+
}) {
19+
return HorizontalSpacing(
20+
left ?? this.left,
21+
right ?? this.right,
22+
);
23+
}
24+
25+
@override
26+
bool operator ==(Object other) =>
27+
identical(this, other) ||
28+
other is HorizontalSpacing &&
29+
left == other.left &&
30+
right == other.right;
31+
32+
@override
33+
int get hashCode => Object.hash(left, right);
1434
}

lib/src/common/structs/vertical_spacing.dart

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,24 @@ class VerticalSpacing {
1111
final double bottom;
1212

1313
static const zero = VerticalSpacing(0, 0);
14+
15+
VerticalSpacing copyWith({
16+
double? top,
17+
double? bottom,
18+
}) {
19+
return VerticalSpacing(
20+
top ?? this.top,
21+
bottom ?? this.bottom,
22+
);
23+
}
24+
25+
@override
26+
bool operator ==(Object other) =>
27+
identical(this, other) ||
28+
other is VerticalSpacing &&
29+
top == other.top &&
30+
bottom == other.bottom;
31+
32+
@override
33+
int get hashCode => Object.hash(top, bottom);
1434
}

lib/src/editor/widgets/default_styles.dart

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,22 @@ class DefaultTextBlockStyle {
6262
/// Decoration, if present, is painted in the content area, excluding
6363
/// any [spacing].
6464
final BoxDecoration? decoration;
65+
66+
DefaultTextBlockStyle copyWith({
67+
TextStyle? style,
68+
HorizontalSpacing? horizontalSpacing,
69+
VerticalSpacing? verticalSpacing,
70+
VerticalSpacing? lineSpacing,
71+
BoxDecoration? decoration,
72+
}) {
73+
return DefaultTextBlockStyle(
74+
style ?? this.style,
75+
horizontalSpacing ?? this.horizontalSpacing,
76+
verticalSpacing ?? this.verticalSpacing,
77+
lineSpacing ?? this.lineSpacing,
78+
decoration ?? this.decoration,
79+
);
80+
}
6581
}
6682

6783
/// Theme data for inline code.
@@ -170,6 +186,30 @@ class DefaultListBlockStyle extends DefaultTextBlockStyle {
170186
final QuillCheckboxBuilder? checkboxUIBuilder;
171187
final LeadingBlockIndentWidth indentWidthBuilder;
172188
final LeadingBlockNumberPointWidth numberPointWidthBuilder;
189+
190+
@override
191+
DefaultListBlockStyle copyWith({
192+
TextStyle? style,
193+
HorizontalSpacing? horizontalSpacing,
194+
VerticalSpacing? verticalSpacing,
195+
VerticalSpacing? lineSpacing,
196+
BoxDecoration? decoration,
197+
QuillCheckboxBuilder? checkboxUIBuilder,
198+
LeadingBlockIndentWidth? indentWidthBuilder,
199+
LeadingBlockNumberPointWidth? numberPointWidthBuilder,
200+
}) {
201+
return DefaultListBlockStyle(
202+
style ?? this.style,
203+
horizontalSpacing ?? this.horizontalSpacing,
204+
verticalSpacing ?? this.verticalSpacing,
205+
lineSpacing ?? this.lineSpacing,
206+
decoration ?? this.decoration,
207+
checkboxUIBuilder ?? this.checkboxUIBuilder,
208+
indentWidthBuilder: indentWidthBuilder ?? this.indentWidthBuilder,
209+
numberPointWidthBuilder:
210+
numberPointWidthBuilder ?? this.numberPointWidthBuilder,
211+
);
212+
}
173213
}
174214

175215
@immutable

lib/src/l10n/generated/quill_localizations.dart

Lines changed: 62 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,15 @@ import 'quill_localizations_zh.dart';
105105
/// property.
106106
abstract class FlutterQuillLocalizations {
107107
FlutterQuillLocalizations(String locale)
108-
: localeName = intl.Intl.canonicalizedLocale(locale.toString());
108+
: localeName = intl.Intl.canonicalizedLocale(locale.toString());
109109

110110
final String localeName;
111111

112112
static FlutterQuillLocalizations? of(BuildContext context) {
113113
return Localizations.of<FlutterQuillLocalizations>(
114-
context, FlutterQuillLocalizations);
114+
context,
115+
FlutterQuillLocalizations,
116+
);
115117
}
116118

117119
static const LocalizationsDelegate<FlutterQuillLocalizations> delegate =
@@ -129,11 +131,11 @@ abstract class FlutterQuillLocalizations {
129131
/// of delegates is preferred or required.
130132
static const List<LocalizationsDelegate<dynamic>> localizationsDelegates =
131133
<LocalizationsDelegate<dynamic>>[
132-
delegate,
133-
GlobalMaterialLocalizations.delegate,
134-
GlobalCupertinoLocalizations.delegate,
135-
GlobalWidgetsLocalizations.delegate,
136-
];
134+
delegate,
135+
GlobalMaterialLocalizations.delegate,
136+
GlobalCupertinoLocalizations.delegate,
137+
GlobalWidgetsLocalizations.delegate,
138+
];
137139

138140
/// A list of this localizations delegate's supported locales.
139141
static const List<Locale> supportedLocales = <Locale>[
@@ -186,7 +188,7 @@ abstract class FlutterQuillLocalizations {
186188
Locale('vi'),
187189
Locale('zh'),
188190
Locale('zh', 'CN'),
189-
Locale('zh', 'HK')
191+
Locale('zh', 'HK'),
190192
];
191193

192194
/// No description provided for @pasteLink.
@@ -833,56 +835,57 @@ class _FlutterQuillLocalizationsDelegate
833835
@override
834836
Future<FlutterQuillLocalizations> load(Locale locale) {
835837
return SynchronousFuture<FlutterQuillLocalizations>(
836-
lookupFlutterQuillLocalizations(locale));
838+
lookupFlutterQuillLocalizations(locale),
839+
);
837840
}
838841

839842
@override
840843
bool isSupported(Locale locale) => <String>[
841-
'ar',
842-
'bg',
843-
'bn',
844-
'bs',
845-
'ca',
846-
'cs',
847-
'da',
848-
'de',
849-
'el',
850-
'en',
851-
'es',
852-
'fa',
853-
'fr',
854-
'gu',
855-
'he',
856-
'hi',
857-
'hr',
858-
'hu',
859-
'id',
860-
'it',
861-
'ja',
862-
'km',
863-
'ko',
864-
'ku',
865-
'mk',
866-
'ms',
867-
'ne',
868-
'nl',
869-
'no',
870-
'pl',
871-
'pt',
872-
'ro',
873-
'ru',
874-
'sk',
875-
'sr',
876-
'sv',
877-
'sw',
878-
'th',
879-
'tk',
880-
'tr',
881-
'uk',
882-
'ur',
883-
'vi',
884-
'zh'
885-
].contains(locale.languageCode);
844+
'ar',
845+
'bg',
846+
'bn',
847+
'bs',
848+
'ca',
849+
'cs',
850+
'da',
851+
'de',
852+
'el',
853+
'en',
854+
'es',
855+
'fa',
856+
'fr',
857+
'gu',
858+
'he',
859+
'hi',
860+
'hr',
861+
'hu',
862+
'id',
863+
'it',
864+
'ja',
865+
'km',
866+
'ko',
867+
'ku',
868+
'mk',
869+
'ms',
870+
'ne',
871+
'nl',
872+
'no',
873+
'pl',
874+
'pt',
875+
'ro',
876+
'ru',
877+
'sk',
878+
'sr',
879+
'sv',
880+
'sw',
881+
'th',
882+
'tk',
883+
'tr',
884+
'uk',
885+
'ur',
886+
'vi',
887+
'zh',
888+
].contains(locale.languageCode);
886889

887890
@override
888891
bool shouldReload(_FlutterQuillLocalizationsDelegate old) => false;
@@ -1028,8 +1031,9 @@ FlutterQuillLocalizations lookupFlutterQuillLocalizations(Locale locale) {
10281031
}
10291032

10301033
throw FlutterError(
1031-
'FlutterQuillLocalizations.delegate failed to load unsupported locale "$locale". This is likely '
1032-
'an issue with the localizations generation tool. Please file an issue '
1033-
'on GitHub with a reproducible sample app and the gen-l10n configuration '
1034-
'that was used.');
1034+
'FlutterQuillLocalizations.delegate failed to load unsupported locale "$locale". This is likely '
1035+
'an issue with the localizations generation tool. Please file an issue '
1036+
'on GitHub with a reproducible sample app and the gen-l10n configuration '
1037+
'that was used.',
1038+
);
10351039
}

0 commit comments

Comments
 (0)