Skip to content

Commit

Permalink
3+++
Browse files Browse the repository at this point in the history
  • Loading branch information
Ellet committed Dec 5, 2023
1 parent daa597f commit 026b58a
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 11 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion example/lib/presentation/quill/quill_toolbar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class MyQuillToolbar extends StatelessWidget {
}

Future<void> onImageInsert(String image, QuillController controller) async {
if (isWeb()) {
if (isWeb() || isHttpBasedUrl(image)) {
controller.insertImageBlock(imageSource: image);
return;
}
Expand Down
3 changes: 1 addition & 2 deletions flutter_quill_extensions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://github.com/natsuk4ze/gal#-get-started> 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
Expand Down
15 changes: 9 additions & 6 deletions flutter_quill_extensions/lib/embeds/image/editor/image_menu.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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();
},
),
Expand Down
16 changes: 15 additions & 1 deletion flutter_quill_extensions/lib/utils/utils.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -48,6 +50,18 @@ class SaveImageResult {
final SaveImageResultMethod method;
}

Future<Uint8List?> 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<SaveImageResult> saveImage({
required String imageUrl,
required ImageSaverService imageSaverService,
Expand Down
3 changes: 2 additions & 1 deletion flutter_quill_extensions/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 026b58a

Please sign in to comment.