From fd2ffcb22c9ab4fab675178718bb81b4f7173281 Mon Sep 17 00:00:00 2001 From: Ellet Date: Sun, 17 Dec 2023 01:08:11 +0300 Subject: [PATCH] Fix image support for web --- CHANGELOG.md | 4 ++++ .../quill/samples/quill_images_sample.dart | 6 ++++-- .../lib/embeds/widgets/image.dart | 8 +++++++- .../lib/flutter_quill_extensions.dart | 11 ++++++----- 4 files changed, 21 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fcd4ebd5..aaf21ad1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ All notable changes to this project will be documented in this file. +## 9.0.3 +* Flutter Quill Extensions: + * Fix file image support for web image emebed builder + ## 9.0.2 * Remove unused properties in the `QuillToolbarSelectHeaderStyleDropdownButton` * Fix the `QuillSimpleToolbar` when `useMaterial3` is false, please upgrade to the latest version of flutter for better support diff --git a/example/lib/presentation/quill/samples/quill_images_sample.dart b/example/lib/presentation/quill/samples/quill_images_sample.dart index 0395af1e..bee33f3c 100644 --- a/example/lib/presentation/quill/samples/quill_images_sample.dart +++ b/example/lib/presentation/quill/samples/quill_images_sample.dart @@ -12,8 +12,10 @@ final quillImagesSample = [ {'insert': '\n'}, { 'insert': { - 'image': - 'https://helpx.adobe.com/content/dam/help/en/photoshop/using/convert-color-image-black-white/jcr_content/main-pars/before_and_after/image-before/Landscape-Color.jpg' + 'image': true + ? 'https://upload.wikimedia.org/wikipedia/commons/b/b6/Image_created_with_a_mobile_phone.png' + // ignore: dead_code + : 'https://helpx.adobe.com/content/dam/help/en/photoshop/using/convert-color-image-black-white/jcr_content/main-pars/before_and_after/image-before/Landscape-Color.jpg' }, 'attributes': { 'width': '250', diff --git a/flutter_quill_extensions/lib/embeds/widgets/image.dart b/flutter_quill_extensions/lib/embeds/widgets/image.dart index c2d4f240..806ab6cd 100644 --- a/flutter_quill_extensions/lib/embeds/widgets/image.dart +++ b/flutter_quill_extensions/lib/embeds/widgets/image.dart @@ -1,6 +1,7 @@ -import 'dart:convert'; +import 'dart:convert' show base64; import 'dart:io' show File; +import 'package:flutter/foundation.dart' show kIsWeb; import 'package:flutter/material.dart'; import 'package:flutter_quill/flutter_quill.dart'; import 'package:photo_view/photo_view.dart'; @@ -53,6 +54,11 @@ ImageProvider getImageProviderByImageSource( if (imageSource.startsWith(assetsPrefix)) { return AssetImage(imageSource); } + + // File image + if (kIsWeb) { + return NetworkImage(imageSource); + } return FileImage(File(imageSource)); } diff --git a/flutter_quill_extensions/lib/flutter_quill_extensions.dart b/flutter_quill_extensions/lib/flutter_quill_extensions.dart index fc4297d2..00401a0f 100644 --- a/flutter_quill_extensions/lib/flutter_quill_extensions.dart +++ b/flutter_quill_extensions/lib/flutter_quill_extensions.dart @@ -112,11 +112,12 @@ class FlutterQuillEmbeds { /// [QuillEditorWebVideoEmbedBuilder] is the embed builder for handling /// videos iframe on the web. /// - static List editorWebBuilders( - {QuillEditorImageEmbedConfigurations? imageEmbedConfigurations = - const QuillEditorImageEmbedConfigurations(), - QuillEditorWebVideoEmbedConfigurations? videoEmbedConfigurations = - const QuillEditorWebVideoEmbedConfigurations()}) { + static List editorWebBuilders({ + QuillEditorImageEmbedConfigurations? imageEmbedConfigurations = + const QuillEditorImageEmbedConfigurations(), + QuillEditorWebVideoEmbedConfigurations? videoEmbedConfigurations = + const QuillEditorWebVideoEmbedConfigurations(), + }) { if (!kIsWeb) { throw UnsupportedError( 'The editorsWebBuilders() is only for web, please use editorBuilders() '