fireproof 0.0.2+7
fireproof: ^0.0.2+7 copied to clipboard
A builder used to create type safe bindings between models and Firestore
fireproof (Work in progress) #
A builder used to create type safe bindings between models and Firestore. This package will likely stay in beta until static metaprogramming (currently in the language funnel of dartlang) is a thing and all builders here can be moved to that.
Getting Started #
This package builds type safe counterparts of DocumentReference, DocumentQuerySnapshot, etc.
After creating a base class, annotate a complementary class with @fireproof. This class will in theory be a QuerySnapshot whose dynamic data()? will be replaced by Model data.
@freezed
class UserBase with _$UserBase {
const factory UserBase({
required String name,
required String email,
}) = _UserBase;
factory UserBase.fromJson(Map<String, dynamic> json) =>
_$UserBaseFromJson(json);
}
@fireproof
abstract class User with _$User {
factory User({
required UserBase data,
required DocumentSnapshot snapshot,
}) = _User;
@Collection(name: 'badges')
BadgesCollection<Badge> get badges;
factory User.fromSnapshot(DocumentSnapshot snapshot) =>
_$UserFromSnapshot(snapshot);
}
Now run
flutter pub run build_runner