Skip to content

Add copyWith methods to DefaultStyles, HorizontalSpacing, and VerticalSpacing #2550

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- `copyWith` methods to `HorizontalSpacing`, `VerticalSpacing`, `DefaultTextBlockStyle`, and `DefaultListBlockStyle` for immutable updates of properties [#2550](https://github.com/singerdmx/flutter-quill/pull/2550).

## [11.4.0] - 2025-04-23

### Added
Expand Down
20 changes: 20 additions & 0 deletions lib/src/common/structs/horizontal_spacing.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,24 @@ class HorizontalSpacing {
final double right;

static const zero = HorizontalSpacing(0, 0);

HorizontalSpacing copyWith({
double? left,
double? right,
}) {
return HorizontalSpacing(
left ?? this.left,
right ?? this.right,
);
}

@override
bool operator ==(Object other) =>
identical(this, other) ||
other is HorizontalSpacing &&
left == other.left &&
right == other.right;

@override
int get hashCode => Object.hash(left, right);
}
20 changes: 20 additions & 0 deletions lib/src/common/structs/vertical_spacing.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,24 @@ class VerticalSpacing {
final double bottom;

static const zero = VerticalSpacing(0, 0);

VerticalSpacing copyWith({
double? top,
double? bottom,
}) {
return VerticalSpacing(
top ?? this.top,
bottom ?? this.bottom,
);
}

@override
bool operator ==(Object other) =>
identical(this, other) ||
other is VerticalSpacing &&
top == other.top &&
bottom == other.bottom;

@override
int get hashCode => Object.hash(top, bottom);
}
40 changes: 40 additions & 0 deletions lib/src/editor/widgets/default_styles.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,22 @@ class DefaultTextBlockStyle {
/// Decoration, if present, is painted in the content area, excluding
/// any [spacing].
final BoxDecoration? decoration;

DefaultTextBlockStyle copyWith({
TextStyle? style,
HorizontalSpacing? horizontalSpacing,
VerticalSpacing? verticalSpacing,
VerticalSpacing? lineSpacing,
BoxDecoration? decoration,
}) {
return DefaultTextBlockStyle(
style ?? this.style,
horizontalSpacing ?? this.horizontalSpacing,
verticalSpacing ?? this.verticalSpacing,
lineSpacing ?? this.lineSpacing,
decoration ?? this.decoration,
);
}
}

/// Theme data for inline code.
Expand Down Expand Up @@ -170,6 +186,30 @@ class DefaultListBlockStyle extends DefaultTextBlockStyle {
final QuillCheckboxBuilder? checkboxUIBuilder;
final LeadingBlockIndentWidth indentWidthBuilder;
final LeadingBlockNumberPointWidth numberPointWidthBuilder;

@override
DefaultListBlockStyle copyWith({
TextStyle? style,
HorizontalSpacing? horizontalSpacing,
VerticalSpacing? verticalSpacing,
VerticalSpacing? lineSpacing,
BoxDecoration? decoration,
QuillCheckboxBuilder? checkboxUIBuilder,
LeadingBlockIndentWidth? indentWidthBuilder,
LeadingBlockNumberPointWidth? numberPointWidthBuilder,
}) {
return DefaultListBlockStyle(
style ?? this.style,
horizontalSpacing ?? this.horizontalSpacing,
verticalSpacing ?? this.verticalSpacing,
lineSpacing ?? this.lineSpacing,
decoration ?? this.decoration,
checkboxUIBuilder ?? this.checkboxUIBuilder,
indentWidthBuilder: indentWidthBuilder ?? this.indentWidthBuilder,
numberPointWidthBuilder:
numberPointWidthBuilder ?? this.numberPointWidthBuilder,
);
}
}

@immutable
Expand Down
120 changes: 62 additions & 58 deletions lib/src/l10n/generated/quill_localizations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,15 @@ import 'quill_localizations_zh.dart';
/// property.
abstract class FlutterQuillLocalizations {
FlutterQuillLocalizations(String locale)
: localeName = intl.Intl.canonicalizedLocale(locale.toString());
: localeName = intl.Intl.canonicalizedLocale(locale.toString());

final String localeName;

static FlutterQuillLocalizations? of(BuildContext context) {
return Localizations.of<FlutterQuillLocalizations>(
context, FlutterQuillLocalizations);
context,
FlutterQuillLocalizations,
);
}

static const LocalizationsDelegate<FlutterQuillLocalizations> delegate =
Expand All @@ -129,11 +131,11 @@ abstract class FlutterQuillLocalizations {
/// of delegates is preferred or required.
static const List<LocalizationsDelegate<dynamic>> localizationsDelegates =
<LocalizationsDelegate<dynamic>>[
delegate,
GlobalMaterialLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
];
delegate,
GlobalMaterialLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
];

/// A list of this localizations delegate's supported locales.
static const List<Locale> supportedLocales = <Locale>[
Expand Down Expand Up @@ -186,7 +188,7 @@ abstract class FlutterQuillLocalizations {
Locale('vi'),
Locale('zh'),
Locale('zh', 'CN'),
Locale('zh', 'HK')
Locale('zh', 'HK'),
];

/// No description provided for @pasteLink.
Expand Down Expand Up @@ -833,56 +835,57 @@ class _FlutterQuillLocalizationsDelegate
@override
Future<FlutterQuillLocalizations> load(Locale locale) {
return SynchronousFuture<FlutterQuillLocalizations>(
lookupFlutterQuillLocalizations(locale));
lookupFlutterQuillLocalizations(locale),
);
}

@override
bool isSupported(Locale locale) => <String>[
'ar',
'bg',
'bn',
'bs',
'ca',
'cs',
'da',
'de',
'el',
'en',
'es',
'fa',
'fr',
'gu',
'he',
'hi',
'hr',
'hu',
'id',
'it',
'ja',
'km',
'ko',
'ku',
'mk',
'ms',
'ne',
'nl',
'no',
'pl',
'pt',
'ro',
'ru',
'sk',
'sr',
'sv',
'sw',
'th',
'tk',
'tr',
'uk',
'ur',
'vi',
'zh'
].contains(locale.languageCode);
'ar',
'bg',
'bn',
'bs',
'ca',
'cs',
'da',
'de',
'el',
'en',
'es',
'fa',
'fr',
'gu',
'he',
'hi',
'hr',
'hu',
'id',
'it',
'ja',
'km',
'ko',
'ku',
'mk',
'ms',
'ne',
'nl',
'no',
'pl',
'pt',
'ro',
'ru',
'sk',
'sr',
'sv',
'sw',
'th',
'tk',
'tr',
'uk',
'ur',
'vi',
'zh',
].contains(locale.languageCode);

@override
bool shouldReload(_FlutterQuillLocalizationsDelegate old) => false;
Expand Down Expand Up @@ -1028,8 +1031,9 @@ FlutterQuillLocalizations lookupFlutterQuillLocalizations(Locale locale) {
}

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