diff --git a/example/lib/screens/settings/cubit/settings_cubit.dart b/example/lib/screens/settings/cubit/settings_cubit.dart index 11bd2042..ab4937ce 100644 --- a/example/lib/screens/settings/cubit/settings_cubit.dart +++ b/example/lib/screens/settings/cubit/settings_cubit.dart @@ -1,13 +1,12 @@ -import 'package:bloc/bloc.dart'; import 'package:flutter/material.dart' show ThemeMode; import 'package:freezed_annotation/freezed_annotation.dart'; -import 'package:hydrated_bloc/hydrated_bloc.dart' show HydratedMixin; +import 'package:hydrated_bloc/hydrated_bloc.dart' show HydratedCubit; part 'settings_state.dart'; part 'settings_cubit.freezed.dart'; part 'settings_cubit.g.dart'; -class SettingsCubit extends Cubit with HydratedMixin { +class SettingsCubit extends HydratedCubit { SettingsCubit() : super(const SettingsState()); void updateSettings(SettingsState newSettingsState) { diff --git a/flutter_quill_extensions/lib/embeds/image/editor/image_menu.dart b/flutter_quill_extensions/lib/embeds/image/editor/image_menu.dart index bc1e1414..e8cc92b9 100644 --- a/flutter_quill_extensions/lib/embeds/image/editor/image_menu.dart +++ b/flutter_quill_extensions/lib/embeds/image/editor/image_menu.dart @@ -96,9 +96,10 @@ class ImageOptionsMenu extends StatelessWidget { ); final data = await convertImageToUint8List(image); + final clipboard = SystemClipboard.instance; if (data != null) { final item = DataWriterItem()..add(Formats.png(data)); - await ClipboardWriter.instance.write([item]); + await clipboard?.write([item]); } navigator.pop(); }, diff --git a/lib/src/l10n/generated/quill_localizations_ar.dart b/lib/src/l10n/generated/quill_localizations_ar.dart index c5b87a49..6f21e8a8 100644 --- a/lib/src/l10n/generated/quill_localizations_ar.dart +++ b/lib/src/l10n/generated/quill_localizations_ar.dart @@ -137,25 +137,25 @@ class FlutterQuillLocalizationsAr extends FlutterQuillLocalizations { String get headerStyle => 'ستايل العنوان'; @override - String get normal => 'Normal'; + String get normal => 'عادي'; @override - String get heading1 => 'Heading 1'; + String get heading1 => 'ترويسة ١'; @override - String get heading2 => 'Heading 2'; + String get heading2 => 'ترويسة ٢'; @override - String get heading3 => 'Heading 3'; + String get heading3 => 'ترويسة ٣'; @override - String get heading4 => 'Heading 4'; + String get heading4 => 'ترويسة ٤'; @override - String get heading5 => 'Heading 5'; + String get heading5 => 'ترويسة ٥'; @override - String get heading6 => 'Heading 6'; + String get heading6 => 'ترويسة ٦'; @override String get numberedList => 'قائمة مرقمة'; @@ -249,20 +249,20 @@ class FlutterQuillLocalizationsAr extends FlutterQuillLocalizations { String get insertImage => 'إدراج صورة'; @override - String get pickAPhotoFromYourGallery => 'Pick a photo from your gallery'; + String get pickAPhotoFromYourGallery => 'اختيار صورة من معرض الصور'; @override - String get takeAPhotoUsingYourCamera => 'Take a photo using your camera'; + String get takeAPhotoUsingYourCamera => 'التقاط صورة باستخدام الكاميرا'; @override - String get pasteAPhotoUsingALink => 'Paste a photo using a link'; + String get pasteAPhotoUsingALink => 'لصق صورة باستخدام رابط'; @override - String get pickAVideoFromYourGallery => 'Pick a video from your gallery'; + String get pickAVideoFromYourGallery => 'اختيار فيديو من معرض الفيديو'; @override - String get recordAVideoUsingYourCamera => 'Record a video using your camera'; + String get recordAVideoUsingYourCamera => 'تسجيل فيديو باستخدام الكاميرا'; @override - String get pasteAVideoUsingALink => 'Paste a video using a link'; + String get pasteAVideoUsingALink => 'لصق فيديو باستخدام رابط'; } diff --git a/lib/src/l10n/quill_ar.arb b/lib/src/l10n/quill_ar.arb index dd2e0911..83c4b460 100644 --- a/lib/src/l10n/quill_ar.arb +++ b/lib/src/l10n/quill_ar.arb @@ -73,6 +73,19 @@ "photo": "صورة", "image": "صورة", "caseSensitivityAndWholeWordSearch": "حالة الحساسية والبحث عن كلمة كاملة", - "insertImage": "إدراج صورة" + "insertImage": "إدراج صورة", + "normal": "عادي", + "heading1": "ترويسة ١", + "heading2": "ترويسة ٢", + "heading3": "ترويسة ٣", + "heading4": "ترويسة ٤", + "heading5": "ترويسة ٥", + "heading6": "ترويسة ٦", + "pickAPhotoFromYourGallery": "اختيار صورة من معرض الصور", + "takeAPhotoUsingYourCamera": "التقاط صورة باستخدام الكاميرا", + "pasteAPhotoUsingALink": "لصق صورة باستخدام رابط", + "pickAVideoFromYourGallery": "اختيار فيديو من معرض الفيديو", + "recordAVideoUsingYourCamera": "تسجيل فيديو باستخدام الكاميرا", + "pasteAVideoUsingALink": "لصق فيديو باستخدام رابط" } \ No newline at end of file diff --git a/lib/src/l10n/untranslated.json b/lib/src/l10n/untranslated.json index 3b002d3e..09698365 100644 --- a/lib/src/l10n/untranslated.json +++ b/lib/src/l10n/untranslated.json @@ -1,20 +1,4 @@ { - "ar": [ - "normal", - "heading1", - "heading2", - "heading3", - "heading4", - "heading5", - "heading6", - "pickAPhotoFromYourGallery", - "takeAPhotoUsingYourCamera", - "pasteAPhotoUsingALink", - "pickAVideoFromYourGallery", - "recordAVideoUsingYourCamera", - "pasteAVideoUsingALink" - ], - "bg": [ "normal", "heading1", diff --git a/lib/src/widgets/raw_editor/raw_editor_state.dart b/lib/src/widgets/raw_editor/raw_editor_state.dart index 401e6feb..4b006b6f 100644 --- a/lib/src/widgets/raw_editor/raw_editor_state.dart +++ b/lib/src/widgets/raw_editor/raw_editor_state.dart @@ -177,21 +177,22 @@ class QuillRawEditorState extends EditorState return; } - if (controller.copiedImageUrl != null) { + // When image copied internally in the editor + final copiedImageUrl = controller.copiedImageUrl; + if (copiedImageUrl != null) { final index = textEditingValue.selection.baseOffset; final length = textEditingValue.selection.extentOffset - index; - final copied = controller.copiedImageUrl!; controller.replaceText( index, length, - BlockEmbed.image(copied.url), + BlockEmbed.image(copiedImageUrl.url), null, ); - if (copied.styleString.isNotEmpty) { + if (copiedImageUrl.styleString.isNotEmpty) { controller.formatText( getEmbedNode(controller, index + 1).offset, 1, - StyleAttribute(copied.styleString), + StyleAttribute(copiedImageUrl.styleString), ); } controller.copiedImageUrl = null; @@ -206,46 +207,49 @@ class QuillRawEditorState extends EditorState return; } - // TODO: Bug, Doesn't replace the selected text, it just add a new one + final clipboard = SystemClipboard.instance; - final reader = await ClipboardReader.readClipboard(); - if (reader.canProvide(Formats.htmlText)) { - final html = await reader.readValue(Formats.htmlText); - if (html == null) { - return; - } - final deltaFromCliboard = Document.fromHtml(html); - var newDelta = Delta(); - newDelta = newDelta.compose(deltaFromCliboard); - if (!controller.document.isEmpty()) { - newDelta = newDelta.compose(controller.document.toDelta()); - } + if (clipboard != null) { + // TODO: Bug, Doesn't replace the selected text, it just add a new one + final reader = await clipboard.read(); + if (reader.canProvide(Formats.htmlText)) { + final html = await reader.readValue(Formats.htmlText); + if (html == null) { + return; + } + final deltaFromClipboard = Document.fromHtml(html); + var newDelta = Delta(); + newDelta = newDelta.compose(deltaFromClipboard); + if (!controller.document.isEmpty()) { + newDelta = newDelta.compose(controller.document.toDelta()); + } - controller - ..setContents( - newDelta, - ) - ..updateSelection( - TextSelection.collapsed( - offset: controller.document.length, - ), - ChangeSource.local, - ); + controller + ..setContents( + newDelta, + ) + ..updateSelection( + TextSelection.collapsed( + offset: controller.document.length, + ), + ChangeSource.local, + ); - bringIntoView(textEditingValue.selection.extent); + bringIntoView(textEditingValue.selection.extent); - // Collapse the selection and hide the toolbar and handles. - userUpdateTextEditingValue( - TextEditingValue( - text: textEditingValue.text, - selection: TextSelection.collapsed( - offset: textEditingValue.selection.end, + // Collapse the selection and hide the toolbar and handles. + userUpdateTextEditingValue( + TextEditingValue( + text: textEditingValue.text, + selection: TextSelection.collapsed( + offset: textEditingValue.selection.end, + ), ), - ), - cause, - ); + cause, + ); - return; + return; + } } // Snapshot the input before using `await`. @@ -279,25 +283,27 @@ class QuillRawEditorState extends EditorState final onImagePaste = widget.configurations.onImagePaste; if (onImagePaste != null) { - final reader = await ClipboardReader.readClipboard(); - if (!reader.canProvide(Formats.png)) { - return; - } - reader.getFile(Formats.png, (value) async { - final image = value; - - final imageUrl = await onImagePaste(await image.readAll()); - if (imageUrl == null) { + if (clipboard != null) { + final reader = await clipboard.read(); + if (!reader.canProvide(Formats.png)) { return; } + reader.getFile(Formats.png, (value) async { + final image = value; - controller.replaceText( - textEditingValue.selection.end, - 0, - BlockEmbed.image(imageUrl), - null, - ); - }); + final imageUrl = await onImagePaste(await image.readAll()); + if (imageUrl == null) { + return; + } + + controller.replaceText( + textEditingValue.selection.end, + 0, + BlockEmbed.image(imageUrl), + null, + ); + }); + } } }