0

I'm busy with my first flutter app and have a question as to how set up the architecture to properly manage images/media within the application. I'm using the flutter bloc todos example as a starting point. My question is how do I mange images stored in firestore as entity and model attributes? I've broken my question into the following:

  1. In TodoEntity if I add an image (or list of images) as an attribute, what is the correct class to use (Image)? Or should I just store the URL as a String?
    class TodoEntity extends Equatable {
      final bool complete;
      final String id;
      final Image image; // this bit is where I'm lost
      final String note;
      final String task;
  1. Then in my Todo class, how is this image stored? Again Image or URL? I assume the toEntity() and FromEntity() methods is where the conversion would happen.

  2. In the case where I have a "parent" class, for example ListOfTodos which has a List<Todo> todos attribute, how would that be managed in this context? Should the ListOfTodosEntity class store the IDs of the todos and collect them from the DB in the fromEntity() method?

My idea is to store a URL in the Entity class and convert it to an Image object in the Todo class within the fromEntity method? Is this the correct idea?

Any help is greatly appreciated. If you happen to have an example where this is done, please provide a link as I was unable to find one.

TM00
  • 1,330
  • 1
  • 14
  • 26
  • You should use an image url in your entity and use this url in your UI to show the image content. If you want to cache image, also some libs support image caching – Yauhen Sampir Feb 29 '20 at 13:43
  • @YauhenSampir thanks for the comment. So basically I only load the image from the URL when its displayed. Will this be the same with locally stored images where the URL will be replaced with the filepath? – TM00 Feb 29 '20 at 15:14

0 Answers0