Git Product home page Git Product logo

firebase_image's Introduction

Handling of images stored in Firebase storage. Bundled with an extension of Firestore Model to also handle photo fields.

The FirebasePhoto references both a thumbnail and a regular image. When a regular image decodes, the image provider first attempts to decode the large version on devices with high dpi.

Assumed storage paths

Firebase Image references assume the image is stored in your default Firebase storage bucket, in path equal to the FirestoreModel reference path.

For example a document of the user model below would be referenced in Firestore at users/dbf523y8, so the photo in Storage would be at users/dbf523y8/photo/0/198673a755/reg.

photo/0 points to photo of key 0. Photos have string keys to allow for multiple photos while still easily preserving their positions.

Switching Firebase Image

SwitchingFirebaseImage extends SwitchingImage to first load a thumbnail, if it's already cached and not the regular photo, then load the regular photo. This allows seamless transitions from list tiles to full pages.

Extending FirestorePhotoModel

Check models in the Flutter Firestore example app.

@JsonSerializable()
class User extends _User with _$User {
  static final collection = FirebaseFirestore.instance.collection('users');

  /// Create [User] from json
  static User fromJson(Map<String, dynamic> json) => _$UserFromJson(json);

  /// Convert [User] to json
  Map<String, dynamic> toJson() => _$UserToJson(this);
}

/// [FirestorePhotoModel] observes the fields of [FirestorePhotoImpl], see next example.
abstract class _User extends FirestorePhotoModel<User> with Store {
  @o @JsonKey() String name;
  @o @JsonKey() String description;
  @o @JsonKey(defaultValue: 0) int views = 0;
  @o @JsonKey(defaultValue: 0) int followers = 0;

  @override @a
  void onSnapshot(User x) {
    super.onSnapshot(x);
    name = x.name;
    description = x.description;
    views = x.views;
    followers = x.followers;
  }
}

Implementing Mixin - FirestorePhotoImpl

If you don't intend to decorate the fields as observable or json serializable, just adding FirestorePhotoImpl as a mixin is enough.

Else extend Mixin fields and decorate them like so:

@o @override @JsonKey(defaultValue: <String, FirebasePhoto>{}) @PhotoMapC() Map<String, FirebasePhoto> photos = const <String, FirebasePhoto>{};
@c @override Map<String, FirebasePhotoReference> get media => super.media;
@c @override FirebasePhotoReference get photo => super.photo;

@override @a
void onSnapshot(x) {
  photos = x.photos;
}

firebase_image's People

Contributors

volskaya avatar

Stargazers

 avatar

Watchers

 avatar  avatar

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.