singerdmx / flutter-quill

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

How can I insert a custom image without using flutter_quill_extensions #2245

Closed zhangwenxia closed 2 months ago

zhangwenxia commented 2 months ago

Is there an existing issue for this?

The question

How can I upload a custom image to my server and insert the image address into the editor without using flutter_quill_extensions

EchoEllet commented 2 months ago

Take a look at Custom Embed Blocks. If the only reason that you want to avoid flutter_quill_extensions is build failure, then this will be addressed in the upcoming release.

zhangwenxia commented 2 months ago

Take a look at Custom Embed Blocks. If the only reason that you want to avoid flutter_quill_extensions is build failure, then this will be addressed in the upcoming release.

Is Custom Embed Blocks available in version 10.6.5? Can you provide the full sample code if it is already available? Thank you very much!

EchoEllet commented 2 months ago

See QuillEditorImageEmbedBuilder from flutter_quill_extensions:


ImageProvider getImageProviderFromSource(String imageSource) {

  if (isImageBase64(imageSource)) {
    return MemoryImage(base64.decode(imageSource));
  }

  if (isHttpBasedUrl(imageSource)) {
    return NetworkImage(imageSource);
  }

  if (imageSource.startsWith(assetsPrefix)) {
    return AssetImage(imageSource);
  }

  // File image
  if (kIsWeb) {
    return NetworkImage(imageSource);
  }
  return FileImage(File(imageSource));
}

import 'package:flutter/material.dart';
import 'package:flutter_quill/flutter_quill.dart' hide OptionalSize;
import 'models/image_configurations.dart';
import 'widgets/image.dart';

class QuillEditorImageEmbedBuilder extends EmbedBuilder {
  QuillEditorImageEmbedBuilder();

  @override
  String get key => BlockEmbed.imageType;

  @override
  bool get expanded => false;

  @override
  Widget build(
    BuildContext context,
    QuillController controller,
    Embed node,
    bool readOnly,
    bool inline,
    TextStyle textStyle,
  ) {
    final imageSource = standardizeImageUrl(node.value.data);

    return GestureDetector(
      onTap: () {
        // Show image menu or do something on image click
      },
      child: Image(image: getImageProviderFromSource(imageSource)),
    );
  }
}
CatHood0 commented 2 months ago

Do you solved your issue? Or it still persists? If not i will close it.

EchoEllet commented 2 months ago

The issue is that they don't want to use flutter_quill_extensions due to build failure caused by Cargo and Rust-related in the previous issue. Once #2230 is done we should be able to. We need more time to implement this feature so we also may consider introducing a breaking change in flutter_quill_extensions and remove super_clipboard directly. Provide them with code examples for the implementation as a quick response.

Prefer to not release the incomplete #2230 just to rush a bug fix.

For now, I will close the issue as it answer provided. Feel free to open more reports if you have more issues.