Skip to content

Commit

Permalink
feat: Use quill_native_bridge as default impl in DefaultClipboardServ…
Browse files Browse the repository at this point in the history
…ice, fix related bugs in the extensions package (singerdmx#2230)

* feat(quill_native_bridge): add initial implementation for getClipboardHTML() method channel for Android and iOS, example and Android platform directory

* chore(example): use quill_native_bridge from path in dependency_overrides

* feat: use quill_native_bridge for HTML Clipboard in flutter_quill and the example (initial impl)

* feat(quill_native_bridge): extend the support for macOS.

* chore(example): clear todos in app module build.gradle

* chore(android): additional check before accessing the clip data item

* fix(flutter_quill_extensions): unrelated bug for copying an image (needs further fixes)

* feat: add copyImageToClipboard() method channel, an asset file in the example, and set supported platforms in pubspec.yaml, configure quill_native_bridge example

* docs(readme): add an optional step to configure copying images to the clipboard on Android for quill_native_bridge

* feat: use copyImageToClipboard() in flutter_quill_extensions, fix common issues in the copy image button

* chore: correct name of _loadImageBytesFromImageProvider()

* feat: add web support for copyImageToClipboard()

* feat: (WIP) retrieving image files from the clipboard, simplifying ClipboardService, slightly updating Android, disabling copyImageToClipboard() for web (temporarily). WIP

* chore(example): rename _flutterQuillAssetImage to _kFlutterQuillAssetImage

* chore(example): update error messages in quill_native_bridge example

* feat: add support for gif, fix unhandled exception on Android only when getting an image from the clipboard before closing the app on a new app start, clean up the platform support check

* chore(example): configure the Android example for copying images to the system clipboard, update README.md

* feat: support for web (WIP, will be updated soon)

* chore: annotate ClipboardService and related classes as experimental

* chore: temporarily add dependency_overrides to fix build failure - revert this change later

* feat: separate web implementation from quill_native_bridge into quill_native_bridge_web

* chore: update description of quill_native_bridge_web

* chore(web): avoid using jsify() when possible

* chore: publish and use quill_native_bridge_web in quill_native_bridge, update to the newly published quill_native_bridge in flutter_quill

* docs(readme): use pub.dev link of quill_native_bridge in quill_native_bridge_web

* chore: use .toJS in clipboardItem map (minor change)

* fix: use hosted quill_native_bridge in dependencies and override with the local path in dependency_overrides

* fix: update minimum required version of Flutter/Dart by quill_native_bridge

* test: write basic integration tests for getClipboardImage() and copyImageToClipboard()

* feat: add copyHTMLToClipboard(), add integration tests for copyHTMLToClipboard() and getClipboardHTML(), minor cleanup in the example

* chore: cleanup QuillNativeBridgeWeb, extract mime constants, organize the order of implemented methods

* fix(web): issue caused by previous commit

* docs(web): update methods of QuillNativeBridge to reflect the web support

* chore(android): cleanup the check for HTML from the clipboard in getClipboardHTML

* test: add a test for getClipboardHTML to ensure it's not null only when the HTML item is the last/primary

* ci: attempt to fix CI failure by updating the outdated path of quill_native_bridge after splitting the web implementation

* docs: document why platform implementations of QuillNativeBridgePlatform should extend it rather than implements

* chore(example): add Windows platform runner example using Flutter CLI (change is automated)

* feat: (WIP) add windows experimental support for getClipboardHTML(), new integration test to ensure the HTML is parsable

* fix(docs): update incorrect description of quill_native_bridge_windows in README

* refactor: move plugin platform interface to quill_native_bridge_platform_interface

* chore: (WIP): publish quill_native_bridge 10.7.5

* chore: (WIP) publish quill_native_bridge_web to use quill_native_bridge_platform_interface

* chore(example): add Linux platform runner example using Flutter CLI (change is automated)

* feat(linux): (WIP) highly experimental Linux support using xclip

* fix(windows): non case sensitive check in stripWin32HtmlDescription() suggested by @AtlasAutocode

* chore(example): unrelated change for windows in Flutter Quill example due to using flutter_inappwebview_windows without running the example on windows (outside of this PR)

* chore(android): cleanup onMethodCall() in QuillNativeBridgePlugin

* docs(readme): update docs to reflect the changes

* chore: use hasWebSupport instead of hardcoding the check directly in QuillNativeBridgePlatformFeature.isSupported

* feat: rename MethodChannelQuillNativeBridge.methodChannel to testMethodChannel, check in development mode to ensure that testMethodChannel can be only used in unit tests for non-web platforms

* refactor: move android implementation from quill_native_bridge to quill_native_bridge_android, use pigeon for Android

* chore: update QuillNativeBridgeAndroid.registerWith() assert message

* refactor(apple): move iOS and macOS implementation from quill_native_bridge to quill_native_bridge_ios and quill_native_bridge_macos, use pigeon for iOS and macOS, clean the code and update QuillNativeBridge to QuillNativeBridgeImpl on Android

* chore: add quill_native_bridge_platform_interface in pubspec_overides.yaml of quill_native_bridge

* refactor: rename copyHTMLToClipboard() and getClipboardHTML() to copyHtmlToClipboard() and getClipboardHtml()

* feat: more advanced method to check the platform support check allowing each platform to have its own check, publish a new experimental version of quill_native_version

* chore(analysis): remove unused imports in quill_native_bridge and quill_native_bridge_platform_interface

* fix(ci): temporarily pub get quill_native_bridge packages in main workflow

* chore: format dart pigeon generated files as a workaround to CI failure

* chore(deps): update flutter_lints to 5.0.0 in quill_native_bridge

* refactor(windows): move CloseClipboard() to finally block in getClipboardHtml()

* chore(windows): clear todo related to previous commit

* chore(readme): remove description from the platform support table, use emojis instead of text for readability

* chore(readme): use different emoji for platforms that don't support a feature or are inapplicable in the platform support table

* style(windows): use TEXT and free from win32 instead of toNativeUtf16() and calloc.free(pointer) from ffi

* refactor(windows): only register HTML format id once

* feat(windows): (WIP) highly experimental support for copyHtmlToClipboard(), minor cleanup (need more)

* refactor: extract supported platforms into Set for isSupported()

* chore(windows): add error code in errors using GetLastError()

* chore(windows): avoid passing the locked memory pointer to SetClipboardData() in copyHtmlToClipboard()

* docs(readme): document android platform configuration in quill_native_bridge

* fix(windows): (WIP) GlobalUnlock before SetClipboardData and GlobalFree on SetClipboardData failure

* docs(readme): slightly improve platform configuration docs in quill_native_bridge

* fix(windows): GlobalUnlock() the handle instead of pointer before calling GlobalUnlock()

* chore(android): add reference to Flutter #63533

* chore(android): define package in GeneratedMessages.kt, update related imports

* chore(android): ignore analysis warning for the generated code messages.g.dart

* feat: (WIP) add initial support for getClipboardFiles()

* chore(ci): format generated messages.g.dart file to bypass CI failure

* feat(linux): add support for getClipboardFiles()

* docs: update the old reference of QuillNativeBridgeFeature, add doc comment for the library

* chore(readme): add link for quill_native_bridge, correct minor typo

* chore(docs): minor changes to update the doc comment in QuillController

* chore: move quill_native_bridge to https://github.com/FlutterQuill/quill-native-bridge

* docs(readme): improve the 'Rich Text Paste' section, drop the TODO for providing a way to customize the paste behavior and customize the clipboard operations

* chore: update deprecation message of FlutterQuillExtensions.useSuperClipboardPlugin() to reflect the change

* chore(example): remove the comment of deprecated method FlutterQuillExtensions.useSuperClipboardPlugin()

* chore: rename ClipboardService.copyImageToClipboard() to ClipboardService.copyImage() (non-breaking change)

* chore: add a link to a TODO in DefaultClipboardService._getClipboardFile()
  • Loading branch information
EchoEllet authored and CatHood0 committed Oct 28, 2024
1 parent 241c6fa commit d09e479
Show file tree
Hide file tree
Showing 41 changed files with 269 additions and 3,646 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ jobs:
- name: 📦 Install flutter_quill_test dependencies
run: flutter pub get -C flutter_quill_test

- name: 📦 Install quill_native_bridge dependencies
run: flutter pub get -C quill_native_bridge

- name: 🔍 Run Flutter analysis
run: flutter analyze

Expand Down
66 changes: 57 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ You can join our [Slack Group] for discussion.
- [📦 Embed Blocks](#-embed-blocks)
- [🔄 Conversion to HTML](#-conversion-to-html)
- [📝 Spelling checker](#-spelling-checker)
- [📝 Rich Text Paste](#-rich-text-paste)
- [✂️ Shortcut events](#-shortcut-events)
- [🌐 Translation](#-translation)
- [🧪 Testing](#-testing)
Expand Down Expand Up @@ -108,20 +109,57 @@ dependencies:
The `flutter_quill` package uses the following plugins:

1. [`url_launcher`](https://pub.dev/packages/url_launcher) to open links.
2. [`quill_native_bridge`](https://pub.dev/packages/quill_native_bridge) to access platform-specific APIs for the
1. [`url_launcher`](https://pub.dev/packages/url_launcher): to open links.
2. [`quill_native_bridge`](https://pub.dev/packages/quill_native_bridge): to access platform-specific APIs for the
editor.
3. [`flutter_keyboard_visibility_temp_fork`](https://pub.dev/packages/flutter_keyboard_visibility_temp_fork) to listen for keyboard
visibility
changes.
visibility changes.

All of them don't require any platform-specific setup.
### Android Configuration for `quill_native_bridge`

To support copying images to the clipboard to be accessed by other apps, you need to configure your Android project.
If not set up, a warning will appear in the log during debug mode only.

> [!TIP]
> This is only required on **Android** for this optional feature.
> You should be able to copy images and paste them inside the editor without any additional configuration.

**1. Update `AndroidManifest.xml`**

Open `your_project/android/app/src/main/AndroidManifest.xml` and add the following inside the `<application>` tag:

```xml
<manifest>
<application>
...
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.fileprovider"
android:exported="false"
android:grantUriPermissions="true" >
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths" />
</provider>
...
</application>
</manifest>
```

**2. Create `file_paths.xml`**

Create the file `your_project/android/app/src/main/res/xml/file_paths.xml` with the following content:

```xml
<paths>
<cache-path name="cache" path="." />
</paths>
```

> [!NOTE]
> Starting from Flutter Quill `9.4.x`, [super_clipboard](https://pub.dev/packages/super_clipboard) has been moved
> to [FlutterQuill Extensions], to use rich text pasting, support pasting images, and gif files from external apps or
> websites, take a look
> at `flutter_quill_extensions` Readme.
> [super_clipboard](https://pub.dev/packages/super_clipboard) is no longer required
> in recent versions of Flutter Quill in `flutter_quill` or `flutter_quill_extensions`.
> [`quill_native_bridge`](https://pub.dev/packages/quill_native_bridge) is a plugin that provide clipboard operations functionality for `flutter_quill`.

## 🚀 Usage

Expand Down Expand Up @@ -307,6 +345,16 @@ The following packages can be used:
This feature is currently not implemented and is being planned. Refer to [#2246](https://github.com/singerdmx/flutter-quill/issues/2246)
for discussion.

## 📝 Rich Text Paste

This feature allows the user to paste the content copied from other apps into the editor as rich text.
The plugin [`quill_native_bridge`](https://pub.dev/packages/quill_native_bridge) provides access to the system Clipboard.

> [!IMPORTANT]
> Currently this feature is not supported on the web.
> See [issue #1998](https://github.com/singerdmx/flutter-quill/issues/1998) and [issue #2220](https://github.com/singerdmx/flutter-quill/issues/2220)
for more details

## ✂️ Shortcut events

We can customize some Shorcut events, using the parameters `characterShortcutEvents` or `spaceShortcutEvents` from `QuillEditorConfigurations` to add more functionality to our editor.
Expand Down
11 changes: 11 additions & 0 deletions example/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,16 @@
android:authorities="com.example.example.SuperClipboardDataProvider"
android:exported="true"
android:grantUriPermissions="true" />

<!-- For `quill_native_bridge` plugin https://github.com/FlutterQuill/quill-native-bridge/tree/main/quill_native_bridge#-platform-configuration -->
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.fileprovider"
android:exported="false"
android:grantUriPermissions="true" >
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths" />
</provider>
</application>
</manifest>
3 changes: 3 additions & 0 deletions example/android/app/src/main/res/xml/file_paths.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<paths>
<cache-path name="cache" path="." />
</paths>
3 changes: 0 additions & 3 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import 'package:flutter_localizations/flutter_localizations.dart'
GlobalWidgetsLocalizations;
import 'package:flutter_quill/flutter_quill.dart' show Document;
import 'package:flutter_quill/translations.dart' show FlutterQuillLocalizations;
import 'package:flutter_quill_extensions/flutter_quill_extensions.dart';

import 'screens/home/widgets/home_screen.dart';
import 'screens/quill/quill_screen.dart';
Expand All @@ -20,8 +19,6 @@ import 'screens/settings/widgets/settings_screen.dart';

void main() async {
WidgetsFlutterBinding.ensureInitialized();
// ignore: deprecated_member_use
FlutterQuillExtensions.useSuperClipboardPlugin();
runApp(const MyApp());
}

Expand Down
2 changes: 2 additions & 0 deletions example/macos/Flutter/GeneratedPluginRegistrant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import file_selector_macos
import gal
import irondash_engine_context
import path_provider_foundation
import quill_native_bridge_macos
import share_plus
import sqflite
import super_native_extensions
Expand All @@ -24,6 +25,7 @@ func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
GalPlugin.register(with: registry.registrar(forPlugin: "GalPlugin"))
IrondashEngineContextPlugin.register(with: registry.registrar(forPlugin: "IrondashEngineContextPlugin"))
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
QuillNativeBridgePlugin.register(with: registry.registrar(forPlugin: "QuillNativeBridgePlugin"))
SharePlusMacosPlugin.register(with: registry.registrar(forPlugin: "SharePlusMacosPlugin"))
SqflitePlugin.register(with: registry.registrar(forPlugin: "SqflitePlugin"))
SuperNativeExtensionsPlugin.register(with: registry.registrar(forPlugin: "SuperNativeExtensionsPlugin"))
Expand Down
19 changes: 6 additions & 13 deletions example/macos/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,17 @@ PODS:
- FlutterMacOS
- file_selector_macos (0.0.1):
- FlutterMacOS
- flutter_inappwebview_macos (0.0.1):
- FlutterMacOS
- OrderedSet (~> 5.0)
- FlutterMacOS (1.0.0)
- gal (1.0.0):
- Flutter
- FlutterMacOS
- irondash_engine_context (0.0.1):
- FlutterMacOS
- OrderedSet (5.0.0)
- path_provider_foundation (0.0.1):
- Flutter
- FlutterMacOS
- quill_native_bridge_macos (0.0.1):
- FlutterMacOS
- share_plus (0.0.1):
- FlutterMacOS
- sqflite (0.0.3):
Expand All @@ -35,30 +33,24 @@ DEPENDENCIES:
- desktop_drop (from `Flutter/ephemeral/.symlinks/plugins/desktop_drop/macos`)
- device_info_plus (from `Flutter/ephemeral/.symlinks/plugins/device_info_plus/macos`)
- file_selector_macos (from `Flutter/ephemeral/.symlinks/plugins/file_selector_macos/macos`)
- flutter_inappwebview_macos (from `Flutter/ephemeral/.symlinks/plugins/flutter_inappwebview_macos/macos`)
- FlutterMacOS (from `Flutter/ephemeral`)
- gal (from `Flutter/ephemeral/.symlinks/plugins/gal/darwin`)
- irondash_engine_context (from `Flutter/ephemeral/.symlinks/plugins/irondash_engine_context/macos`)
- path_provider_foundation (from `Flutter/ephemeral/.symlinks/plugins/path_provider_foundation/darwin`)
- quill_native_bridge_macos (from `Flutter/ephemeral/.symlinks/plugins/quill_native_bridge_macos/macos`)
- share_plus (from `Flutter/ephemeral/.symlinks/plugins/share_plus/macos`)
- sqflite (from `Flutter/ephemeral/.symlinks/plugins/sqflite/darwin`)
- super_native_extensions (from `Flutter/ephemeral/.symlinks/plugins/super_native_extensions/macos`)
- url_launcher_macos (from `Flutter/ephemeral/.symlinks/plugins/url_launcher_macos/macos`)
- video_player_avfoundation (from `Flutter/ephemeral/.symlinks/plugins/video_player_avfoundation/darwin`)

SPEC REPOS:
trunk:
- OrderedSet

EXTERNAL SOURCES:
desktop_drop:
:path: Flutter/ephemeral/.symlinks/plugins/desktop_drop/macos
device_info_plus:
:path: Flutter/ephemeral/.symlinks/plugins/device_info_plus/macos
file_selector_macos:
:path: Flutter/ephemeral/.symlinks/plugins/file_selector_macos/macos
flutter_inappwebview_macos:
:path: Flutter/ephemeral/.symlinks/plugins/flutter_inappwebview_macos/macos
FlutterMacOS:
:path: Flutter/ephemeral
gal:
Expand All @@ -67,6 +59,8 @@ EXTERNAL SOURCES:
:path: Flutter/ephemeral/.symlinks/plugins/irondash_engine_context/macos
path_provider_foundation:
:path: Flutter/ephemeral/.symlinks/plugins/path_provider_foundation/darwin
quill_native_bridge_macos:
:path: Flutter/ephemeral/.symlinks/plugins/quill_native_bridge_macos/macos
share_plus:
:path: Flutter/ephemeral/.symlinks/plugins/share_plus/macos
sqflite:
Expand All @@ -82,12 +76,11 @@ SPEC CHECKSUMS:
desktop_drop: 69eeff437544aa619c8db7f4481b3a65f7696898
device_info_plus: ce1b7762849d3ec103d0e0517299f2db7ad60720
file_selector_macos: 54fdab7caa3ac3fc43c9fac4d7d8d231277f8cf2
flutter_inappwebview_macos: 9600c9df9fdb346aaa8933812009f8d94304203d
FlutterMacOS: 8f6f14fa908a6fb3fba0cd85dbd81ec4b251fb24
gal: 61e868295d28fe67ffa297fae6dacebf56fd53e1
irondash_engine_context: da62996ee25616d2f01bbeb85dc115d813359478
OrderedSet: aaeb196f7fef5a9edf55d89760da9176ad40b93c
path_provider_foundation: 2b6b4c569c0fb62ec74538f866245ac84301af46
quill_native_bridge_macos: f90985c5269ac7ba84d933605b463d96e5f544fe
share_plus: 36537c04ce0c3e3f5bd297ce4318b6d5ee5fd6cf
sqflite: 673a0e54cc04b7d6dba8d24fb8095b31c3a99eec
super_native_extensions: 85efee3a7495b46b04befcfc86ed12069264ebf3
Expand Down
1 change: 0 additions & 1 deletion example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ dependency_overrides:
flutter_quill_test:
path: ../flutter_quill_test


dev_dependencies:
flutter_test:
sdk: flutter
Expand Down
36 changes: 2 additions & 34 deletions flutter_quill_extensions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,6 @@ The package uses the following plugins:
platform-specific setup.
2. [`image_picker`](https://pub.dev/packages/image_picker) for picking images.
See the [Installation](https://pub.dev/packages/image_picker#installation) section.
3. [`super_clipboard`](https://pub.dev/packages/super_clipboard) which needs some setup on Android only, it's used to
support copying images and pasting them into editor, it's also required to support rich text pasting feature on
non-web platforms, Open the [Android Support](https://pub.dev/packages/super_clipboard#android-support) page for
instructions.
The `minSdkVersion` for **Android** is `23` as `super_clipboard` requires it

### Loading Images from the Internet

Expand Down Expand Up @@ -151,35 +146,8 @@ This works only for non-web platforms.

### 📝 Rich Text Paste Feature

The Rich Text Pasting feature requires native code to access
the `Clipboard` data as HTML, the plugin `super_clipboard` is required on all platforms except Web.

This package already includes `super_clipboard` and will be used internally in this package, to use it
in `flutter_quill`, call this function before using any of the widgets or functionalities:

```dart
FlutterQuillExtensions.useSuperClipboardPlugin();
```

`super_clipboard` is a comprehensive plugin that provides many clipboard features for reading and writing rich text,
images and other formats.

Calling this function will allow `flutter_quill` to use modern rich text features to paste HTML and Markdown,
support for GIF files, and other formats.

> [!IMPORTANT]
> On web platforms, you can only get the HTML from `Clipboard` on the
> `paste` event, `super_clipboard`, or any plugin is not required.
> The paste feature will not work using the standard paste hotkey logic.
> As such, you will be unable to use the **Rich Text Paste Feature** on a button or in the web app itself.
> So you might want to either display a dialog when pressing the paste button that explains the limitation and shows the
> hotkey they need to press in order to paste or develop an extension for the browser that bypasses this limitation
> similarly to **Google Docs** and provide a link to install the browser extension.
> See [Issue #1998](https://github.com/singerdmx/flutter-quill/issues/1998) for more details.

> [!NOTE]
> We're still planning on how this should be implemented in
> [Issue #1998](https://github.com/singerdmx/flutter-quill/issues/1998).
The rich text paste feature is now supported directly in `flutter_quill`
as platform code is not bundled with the project.

### 🖼️ Image Assets

Expand Down
11 changes: 7 additions & 4 deletions flutter_quill_extensions/lib/flutter_quill_extensions.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
library;

// ignore: implementation_imports
import 'package:flutter_quill/src/editor_toolbar_controller_shared/clipboard/clipboard_service_provider.dart';
import 'package:flutter_quill/flutter_quill_internal.dart'
show ClipboardServiceProvider;
import 'package:meta/meta.dart' show experimental;

import 'src/editor_toolbar_controller_shared/clipboard/super_clipboard_service.dart';
Expand Down Expand Up @@ -64,8 +64,11 @@ class FlutterQuillExtensions {
/// to allow `flutter_quill` package to use `super_clipboard` plugin
/// to support rich text features, gif and images.
@Deprecated(
'Should not be used anymore as super_clipboard will moved outside of flutter_quill_extensions soon.\n'
'A replacement is being made in https://github.com/singerdmx/flutter-quill/pull/2230',
'The functionality of super_clipboard is now built-in in recent versions of flutter_quill.\n'
'To migrate, remove this function call and see '
'https://pub.dev/packages/quill_native_bridge#-platform-configuration (optional for copying images on Android) to use quill_native_bridge implementation (the new default).\n'
'Or if you want to use super_clipboard implementation (support might discontinued in newer versions), use the package https://pub.dev/packages/quill_super_clipboard\n'
'See https://github.com/singerdmx/flutter-quill/pull/2230 for more details.',
)
@experimental
static void useSuperClipboardPlugin() {
Expand Down
21 changes: 1 addition & 20 deletions flutter_quill_extensions/lib/src/common/utils/utils.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import 'dart:io' show File;

import 'package:cross_file/cross_file.dart';
import 'package:flutter/foundation.dart' show Uint8List, immutable;
import 'package:http/http.dart' as http;
import 'package:flutter/foundation.dart' show immutable;

import '../../editor/image/widgets/image.dart';
import '../../editor_toolbar_shared/image_saver/s_image_saver.dart';
Expand Down Expand Up @@ -51,23 +49,6 @@ 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;
}
// TODO: Add support for all image providers like AssetImage
try {
final file = XFile(image);
return await file.readAsBytes();
} catch (e) {
return null;
}
}

Future<SaveImageResult> saveImage({
required String imageUrl,
required ImageSaverService imageSaverService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ class QuillEditorImageEmbedBuilder extends EmbedBuilder {
bool inline,
TextStyle textStyle,
) {
// assert(!kIsWeb, 'Please provide image EmbedBuilder for Web');

final imageSource = standardizeImageUrl(node.value.data);
final ((imageSize), margin, alignment) = getElementAttributes(
node,
Expand All @@ -40,7 +38,7 @@ class QuillEditorImageEmbedBuilder extends EmbedBuilder {
final width = imageSize.width;
final height = imageSize.height;

final image = getImageWidgetByImageSource(
final imageWidget = getImageWidgetByImageSource(
context: context,
imageSource,
imageProviderBuilder: configurations.imageProviderBuilder,
Expand Down Expand Up @@ -72,6 +70,7 @@ class QuillEditorImageEmbedBuilder extends EmbedBuilder {
imageSize: imageSize,
isReadOnly: readOnly,
imageSaverService: imageSaverService,
imageProvider: imageWidget.image,
),
),
);
Expand All @@ -81,10 +80,10 @@ class QuillEditorImageEmbedBuilder extends EmbedBuilder {
if (margin != null) {
return Padding(
padding: EdgeInsets.all(margin),
child: image,
child: imageWidget,
);
}
return image;
return imageWidget;
},
),
);
Expand Down
Loading

0 comments on commit d09e479

Please sign in to comment.