singerdmx / flutter-quill

Rich text editor for Flutter
https://pub.dev/packages/flutter_quill
MIT License
2.6k stars 839 forks source link

Update example to support image pasting on web #2385

Closed Maksim-Nikolaev closed 5 days ago

Maksim-Nikolaev commented 6 days ago

Description

Update the example main.dart to demonstrate the support of image pasting on web by using in-built dart:html

https://github.com/user-attachments/assets/acc0d8b6-755b-4697-a9d6-1bc7fe7a8098

  // Create a Blob from the image bytes
  final blob = html.Blob([imageBytes], 'image/png');

  // Create a temporary URL for the blob
  final url = html.Url.createObjectUrlFromBlob(blob);

  return url;

Type of Change

Maksim-Nikolaev commented 6 days ago

I went back on the phone and realized that dart:html has to be imported conditionally which adds code complexity and requires some decisions, so it's not good for updating example.

For my project I will use universal_html to get around possible issues

EchoEllet commented 5 days ago

dart:html has to be imported conditionally

How about package:web instead? Which is a replacement for dart:html and support WASM. You will need to use conditional import to not break the compilation for non-web platforms.

Maksim-Nikolaev commented 5 days ago

My main goal was to avoid usage of external dependencies, to make the example as light-weight as possible.

I reopened the PR to show how the conditional imports would work. I checked Android & Web (Chrome) and both are building now while supporting the image pasting.

Feel free to close it if needed.

EchoEllet commented 5 days ago

My main goal was to avoid usage of external dependencies, to make the example as light-weight as possible.

FYI: The web package is Dart's first-party dependency. They didn't make it part of the SDK to keep it more open to contributors, and clients can use newer versions without updating their Dart SDK. The bundle size is the same.

Though I agree this is out of scope for this example, it might be a good idea to move it into an example somewhere else.