Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image example #19

Closed
stanonyime opened this issue Jul 2, 2021 · 9 comments
Closed

Image example #19

stanonyime opened this issue Jul 2, 2021 · 9 comments
Labels
question Further information is requested

Comments

@stanonyime
Copy link

How do you handle image pick?

@featzima
Copy link
Collaborator

featzima commented Jul 2, 2021

We use the file_selector package

@stanonyime
Copy link
Author

What I mean is there is supposed to be a delegate at the Editor class which ties the image handling logic? That seems to be missing? Is there any example somewhere?

@glynskyi glynskyi added the question Further information is requested label Jul 13, 2021
@featzima
Copy link
Collaborator

ZefyrEditor(
  focusNode: FocusNote()
  embedBuilder: ZefyrEditorEmbedBuilder(widget.filesystemRepo),
  // ...
),

class ZefyrEditorEmbedBuilder {
  final FilesystemRepo _filesystemRepo;

  ZefyrEditorEmbedBuilder(this._filesystemRepo);

  Widget call(BuildContext context, EmbedNode node) {
    if (node.value.type == "hr") {
      final theme = ZefyrTheme.of(context)!;
      return Divider(
        height: theme.paragraph.style.fontSize! * theme.paragraph.style.height!,
        thickness: 2,
        color: Colors.grey.shade200,
      );
    }
    if (node.value.type == "image") {
      final filename = node.value.data["source"] as String?;
      return Align(
        alignment: Alignment.centerLeft,
        child: ConstrainedBox(
          constraints: const BoxConstraints(maxHeight: 300),
          child: filename == null ? _buildMissedImage() : _buildExistsImage(filename),
        ),
      );
    }
    throw UnimplementedError('Embeddable type "${node.value.type}" is not supported by default embed '
        'builder of ZefyrEditor. You must pass your own builder function to '
        'embedBuilder property of ZefyrEditor or ZefyrField widgets.');
  }

  Widget _buildExistsImage(String filename) {
    return FutureBuilder<File>(
      future: _filesystemRepo.loadImage(filename),
      builder: (context, file) => file.data == null
          ? Container(
              width: 320,
              height: 240,
              color: Colors.grey.shade50,
              child: const Center(child: CircularProgressIndicator()),
            )
          : Image.file(file.data!),
    );
  }

  Widget _buildMissedImage() {
    return Container(
      width: 320,
      height: 240,
      color: Colors.grey.shade50,
      child: const Center(
        child: Icon(Icons.close, color: Colors.grey),
      ),
    );
  }
}

@cowcomic
Copy link

cowcomic commented Dec 7, 2021

what is FilesystemRepo?
i need complete example code
thx

@glynskyi
Copy link
Owner

glynskyi commented Dec 7, 2021

@cowcomic instead of FilesystemRepo you can use any external source of images. It depends on what you put to embedded object properties. It can be file path or raw bytes from database.

@ruolunhui
Copy link

Hello, I would like to ask how to customize the insert. Using the following two methods to insert the picture and then inserting the picture will report an error
_controller.document.root.insertBefore(lineNode);
_controller.document.insert(0, EmbeddableObject("image",data: {"source":(imageUrl)}, inline: false));

type 'double' is not a subtype of type 'int' in type cast

And the callback will not be triggered after the image is inserted

@Xiangjinxiu
Copy link

controller.document.insert(0, BlockEmbed.image(value.path));

@ManavSarkar
Copy link

but the toolbar doesn't show the image picker icon. Without that, how can we add the functionality?
Is there any way out?

@ManavSarkar
Copy link

@Xiangjinxiu

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

7 participants