From fcd9f19cfeca59b55ab04e5d01ca301b3140e323 Mon Sep 17 00:00:00 2001 From: Okan YILDIRIM <63511519+ragokan@users.noreply.github.com> Date: Mon, 3 Nov 2025 14:54:13 +0300 Subject: [PATCH 1/3] refactor: update localization handling to fall back to English and improve exception messaging --- .../l10n/extensions/localizations_ext.dart | 16 +++++-- test/editor/editor_test.dart | 46 +++++++++---------- 2 files changed, 35 insertions(+), 27 deletions(-) diff --git a/lib/src/l10n/extensions/localizations_ext.dart b/lib/src/l10n/extensions/localizations_ext.dart index 91128d659..5694bd313 100644 --- a/lib/src/l10n/extensions/localizations_ext.dart +++ b/lib/src/l10n/extensions/localizations_ext.dart @@ -1,7 +1,12 @@ import 'package:flutter/widgets.dart' show BuildContext; import '../generated/quill_localizations.dart'; +import '../generated/quill_localizations_en.dart'; +@Deprecated( + 'FlutterQuill now falls back to English strings when the localization ' + 'delegate is missing. This exception will be removed in a future release.', +) class MissingFlutterQuillLocalizationException extends UnimplementedError { MissingFlutterQuillLocalizationException(); @override @@ -13,11 +18,14 @@ class MissingFlutterQuillLocalizationException extends UnimplementedError { } extension LocalizationsExt on BuildContext { - /// Require the [FlutterQuillLocalizations] instance. + static final FlutterQuillLocalizations _fallbackLocalization = + FlutterQuillLocalizationsEn(); + + /// Retrieve the [FlutterQuillLocalizations] instance, falling back to the + /// default English messages if no delegate is registered. /// - /// `loc` is short for `localizations` + /// `loc` is short for `localizations`. FlutterQuillLocalizations get loc { - return FlutterQuillLocalizations.of(this) ?? - (throw MissingFlutterQuillLocalizationException()); + return FlutterQuillLocalizations.of(this) ?? _fallbackLocalization; } } diff --git a/test/editor/editor_test.dart b/test/editor/editor_test.dart index c5d34a8cf..c1330332a 100644 --- a/test/editor/editor_test.dart +++ b/test/editor/editor_test.dart @@ -158,19 +158,12 @@ void main() { await tester.pump(); final exception = tester.takeException(); - expect( - exception, - isNot( - isInstanceOf(), - ), - ); - expect(exception, isNull); }, ); testWidgets( - 'should throw MissingFlutterQuillLocalizationException if the delegate not provided', + 'falls back to English localization if the delegate is not provided', (tester) async { await tester.pumpWidget( MaterialApp( @@ -180,21 +173,22 @@ void main() { ), ); + await tester.pump(); + final exception = tester.takeException(); - expect(exception, isNotNull); - expect( - exception, - isA(), - ); + expect(exception, isNull); + expect(find.text('Font'), findsOneWidget); }, ); testWidgets( - 'should not throw MissingFlutterQuillLocalizationException if the delegate is provided', + 'uses the provided localization delegate when available', (tester) async { await tester.pumpWidget( MaterialApp( + locale: const Locale('es'), + supportedLocales: FlutterQuillLocalizations.supportedLocales, localizationsDelegates: FlutterQuillLocalizations.localizationsDelegates, home: Builder( @@ -203,33 +197,39 @@ void main() { ), ); + await tester.pump(); + final exception = tester.takeException(); expect(exception, isNull); - expect( - exception, - isNot(isA()), - ); + expect(find.text('Fuente'), findsOneWidget); }, ); testWidgets( - 'should throw MissingFlutterQuillLocalizationException if the delegate is not provided', + 'fallback localization provides interpolated messages when delegate is missing', (tester) async { + late String resolvedMessage; await tester.pumpWidget( MaterialApp( home: Builder( - builder: (context) => Text(context.loc.font), + builder: (context) { + resolvedMessage = + context.loc.theImageHasBeenSavedAt('/tmp/image.png'); + return const SizedBox.shrink(); + }, ), ), ); + await tester.pump(); + final exception = tester.takeException(); - expect(exception, isNotNull); + expect(exception, isNull); expect( - exception, - isA(), + resolvedMessage, + 'The image has been saved at: /tmp/image.png', ); }, ); From f85dcf1877e645824ffc045181674b565a3a5983 Mon Sep 17 00:00:00 2001 From: Okan YILDIRIM <63511519+ragokan@users.noreply.github.com> Date: Mon, 3 Nov 2025 18:25:29 +0300 Subject: [PATCH 2/3] Fix formatting in pubspec.yaml for flutter_quill --- flutter_quill_extensions/pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flutter_quill_extensions/pubspec.yaml b/flutter_quill_extensions/pubspec.yaml index 6f5cae329..63861f9a1 100644 --- a/flutter_quill_extensions/pubspec.yaml +++ b/flutter_quill_extensions/pubspec.yaml @@ -36,7 +36,7 @@ dependencies: web: ">=0.5.0 <2.0.0" path: ^1.8.0 - flutter_quill: ^11.0.0 + flutter_quill: photo_view: ^0.15.0 # Plugins From 3e52daaa162131fd133c2ea22f73fb64d8573370 Mon Sep 17 00:00:00 2001 From: Okan YILDIRIM <63511519+ragokan@users.noreply.github.com> Date: Mon, 3 Nov 2025 18:26:24 +0300 Subject: [PATCH 3/3] Revert previous change. --- flutter_quill_extensions/pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flutter_quill_extensions/pubspec.yaml b/flutter_quill_extensions/pubspec.yaml index 63861f9a1..6f5cae329 100644 --- a/flutter_quill_extensions/pubspec.yaml +++ b/flutter_quill_extensions/pubspec.yaml @@ -36,7 +36,7 @@ dependencies: web: ">=0.5.0 <2.0.0" path: ^1.8.0 - flutter_quill: + flutter_quill: ^11.0.0 photo_view: ^0.15.0 # Plugins