From 026b58aa0df9a9ce98be36ab46a2fdc4842d3a5c Mon Sep 17 00:00:00 2001 From: Ellet Date: Tue, 5 Dec 2023 14:50:43 +0300 Subject: [PATCH] 3+++ --- CHANGELOG.md | 4 ++++ .../lib/presentation/quill/quill_toolbar.dart | 2 +- flutter_quill_extensions/README.md | 3 +-- .../lib/embeds/image/editor/image_menu.dart | 15 +++++++++------ flutter_quill_extensions/lib/utils/utils.dart | 16 +++++++++++++++- flutter_quill_extensions/pubspec.yaml | 3 ++- 6 files changed, 32 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4363db5a..7132f072 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ All notable changes to this project will be documented in this file. * Breaking Changes: * Rename `QuillToolbar` to `QuillSimpleToolbar` * Rename `QuillBaseToolbar` to `QuillToolbar` + * Replace `pasteboard` with `rich_cliboard` +* Fix a bug in the example when inserting an image from url +* Flutter Quill Extensions: + * Add support for copying the image to the system cliboard ## 9.0.0-dev-2 * An attemp to fix CI automated publishing diff --git a/example/lib/presentation/quill/quill_toolbar.dart b/example/lib/presentation/quill/quill_toolbar.dart index 303e6587..79c38ce1 100644 --- a/example/lib/presentation/quill/quill_toolbar.dart +++ b/example/lib/presentation/quill/quill_toolbar.dart @@ -66,7 +66,7 @@ class MyQuillToolbar extends StatelessWidget { } Future onImageInsert(String image, QuillController controller) async { - if (isWeb()) { + if (isWeb() || isHttpBasedUrl(image)) { controller.insertImageBlock(imageSource: image); return; } diff --git a/flutter_quill_extensions/README.md b/flutter_quill_extensions/README.md index b42c90de..4158462c 100644 --- a/flutter_quill_extensions/README.md +++ b/flutter_quill_extensions/README.md @@ -53,8 +53,7 @@ dependencies: > > 1. We are using the [`gal`](https://github.com/natsuk4ze/) plugin to save images. -> For this to work, you need to add the appropriate permissions -> to your `Info.plist` and `AndroidManifest.xml` files. +> For this to work, you need to add the appropriate configurations > See to add the needed lines. > > 2. We also use [`image_picker`](https://pub.dev/packages/image_picker) plugin for picking images so please make sure to follow the instructions 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 4bcf19b1..bc1e1414 100644 --- a/flutter_quill_extensions/lib/embeds/image/editor/image_menu.dart +++ b/flutter_quill_extensions/lib/embeds/image/editor/image_menu.dart @@ -4,6 +4,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_quill/flutter_quill.dart' show ImageUrl, QuillController, StyleAttribute, getEmbedNode; import 'package:flutter_quill/translations.dart'; +import 'package:super_clipboard/super_clipboard.dart'; import '../../../models/config/editor/image/image.dart'; import '../../../models/config/shared_configurations.dart'; @@ -88,15 +89,17 @@ class ImageOptionsMenu extends StatelessWidget { final navigator = Navigator.of(context); final imageNode = getEmbedNode(controller, controller.selection.start).value; - final imageUrl = imageNode.value.data; + final image = imageNode.value.data; controller.copiedImageUrl = ImageUrl( - imageUrl, + image, getImageStyleString(controller), ); - // TODO: Implement the copy image - // await Clipboard.setData( - // ClipboardData(), - // ); + + final data = await convertImageToUint8List(image); + if (data != null) { + final item = DataWriterItem()..add(Formats.png(data)); + await ClipboardWriter.instance.write([item]); + } navigator.pop(); }, ), diff --git a/flutter_quill_extensions/lib/utils/utils.dart b/flutter_quill_extensions/lib/utils/utils.dart index 12c802a1..b5497033 100644 --- a/flutter_quill_extensions/lib/utils/utils.dart +++ b/flutter_quill_extensions/lib/utils/utils.dart @@ -1,6 +1,8 @@ import 'dart:io' show File; -import 'package:flutter/foundation.dart' show immutable; +import 'package:cross_file/cross_file.dart'; +import 'package:flutter/foundation.dart' show Uint8List, immutable; +import 'package:http/http.dart' as http; import '../embeds/widgets/image.dart'; import '../services/image_saver/s_image_saver.dart'; @@ -48,6 +50,18 @@ class SaveImageResult { final SaveImageResultMethod method; } +Future convertImageToUint8List(String image) async { + if (isHttpBasedUrl(image)) { + final response = await http.get(Uri.parse(image)); + if (response.statusCode == 200) { + return Uint8List.fromList(response.bodyBytes); + } + return null; + } + final file = XFile(image); + return await file.readAsBytes(); +} + Future saveImage({ required String imageUrl, required ImageSaverService imageSaverService, diff --git a/flutter_quill_extensions/pubspec.yaml b/flutter_quill_extensions/pubspec.yaml index 7453fe16..0fb58c4d 100644 --- a/flutter_quill_extensions/pubspec.yaml +++ b/flutter_quill_extensions/pubspec.yaml @@ -41,9 +41,10 @@ dependencies: # Plugins video_player: ^2.8.1 youtube_player_flutter: ^8.1.2 + url_launcher: ^6.2.1 + super_clipboard: ^0.7.3 gal: ^2.1.3 image_picker: ^1.0.4 - url_launcher: ^6.2.1 dev_dependencies: flutter_test: