Giter VIP home page Giter VIP logo

Comments (2)

pulyaevskiy avatar pulyaevskiy commented on August 25, 2024 12

Short answer is: yes.

Note I'd recommend using latest version from master branch for the following.

You'd need to implement your own ZefyrImageDelegate which looks like this:

abstract class ZefyrImageDelegate<S> {
  /// Builds image widget for specified [imageSource] and [context].
  Widget buildImage(BuildContext context, String imageSource);

  /// Picks an image from specified [source].
  ///
  /// Returns unique string key for the selected image. Returned key is stored
  /// in the document.
  Future<String> pickImage(S source);
}

There is default implementation which only handles local File and exists mostly as an example. In your app you'd definitely want roll your own. Here is how default delegate looks like:

class ZefyrDefaultImageDelegate implements ZefyrImageDelegate<ImageSource> {
  @override
  Widget buildImage(BuildContext context, String imageSource) {
    final file = new File.fromUri(Uri.parse(imageSource));
    final image = new FileImage(file);
    return new Image(image: image);
  }

  @override
  Future<String> pickImage(ImageSource source) async {
    final file = await ImagePicker.pickImage(source: source);
    if (file == null) return null;
    return file.uri.toString();
  }
}

As you can see it uses image_picker plugin. In your own version you are free to use whichever plugin suites your needs.

Now, the main thing to know here is how image information is stored in produced Delta. In short,

  1. The string returned from pickImage gets stored in your document. It is up to you to define how this string looks like. It can be an absolute file path, an HTTP link or some unique key.
  2. When editor needs to render the image it calls buildImage of your delegate with the string key you previously returned from pickImage. Here you simply need to return an Image widget configured with appropriate ImageProvider. So, if you used HTTP link you can use NetworkImage.

You can have more complex flows here as well. For instance, in my project I use Firebase Storage to upload images. When user picks a new image I return unique ID of that image generated by Firebase Storage. Then in buildImage I create a custom Image widget which is responsible for caching images locally and showing simple upload progress indicator for newly added images.

Hope this helps.

from zefyr.

bravekingzhang avatar bravekingzhang commented on August 25, 2024

thank you!

from zefyr.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.