Skip to content

Instantly share code, notes, and snippets.

@marcossevilla
Created February 4, 2021 17:28
Show Gist options
  • Save marcossevilla/90a33b7c4274c2cebf33777582824b2d to your computer and use it in GitHub Desktop.
Save marcossevilla/90a33b7c4274c2cebf33777582824b2d to your computer and use it in GitHub Desktop.
import 'package:cloud_firestore/cloud_firestore.dart' show DocumentSnapshot;
import 'package:freezed_annotation/freezed_annotation.dart';
part 'store_item.freezed.dart';
part 'store_item.g.dart';
@freezed
abstract class StoreItem with _$StoreItem {
const factory StoreItem.model({
@required int id,
@required String name,
}) = StoreItemModel;
const factory StoreItem.firestore({
@required int id,
@required String name,
@required bool isAvailable,
}) = StoreItemFirestore;
factory StoreItem.fromJson(Map<String, dynamic> json) =>
_$StoreItemFromJson(json);
factory StoreItem.fromFirestore(DocumentSnapshot doc) {
return StoreItemFirestore.fromJson(doc.data());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment