InterfacePlus class abstract
Abstract interface that enforces consistent model structure for Firestore operations.
All models used with FirestorePlus must implement this interface to ensure:
- Proper serialization/deserialization
- Consistent document ID handling
- Type-safe operations
Example Implementation
class User implements InterfacePlus {
User({required this.uid, required this.name, required this.email});
@override
String? uid;
final String name;
final String email;
@override
Map<String, dynamic> get json => {
'uid': uid,
'name': name,
'email': email,
};
static User withMap(Map<String, dynamic> map) => User(
uid: map['uid'],
name: map['name'],
email: map['email'],
);
}
Required Implementation
- uid: Document identifier (can be null for new documents)
- json: Serialization method for Firestore storage
- withMap: Static constructor for deserialization from Firestore data
Best Practices
- Make
uidnullable and final in your constructor - Use meaningful property names in your
jsongetter - Handle type casting safely in
withMap(e.g.,(map['price'] as num).toDouble()) - Add business logic methods to your model classes
- Use the
withMapmethod as a static factory constructor
Constructors
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
-
json
→ Map<
String, dynamic> -
Factory constructor for creating instances from Firestore data.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- uid ↔ String?
-
Document identifier for Firestore operations.
getter/setter pair
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
String representation of the model for debugging and logging.
override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited