I have this function with scoped model in which I want to have a firebase increment to snapshot when the button is pressed, but It returns ˜The getter 'documentID' was called on null.˜, it changes the state of my icon but the number is not incremented. If I give the name of the document it works fine, but I don't want to specify it. Any thoughts on what could be the solution?
void main() {
runApp(EaiCasimiro());
}
class EaiCasimiro extends StatelessWidget {
@override
Widget build(BuildContext context) {
return ScopedModel<LikesModel>(
model: LikesModel(),
child: MaterialApp(
title: "E aí, Casimiro?",
home: HomeScreen(),
debugShowCheckedModeBanner: false,
)
);
}
}
class LikesModel extends Model {
DocumentSnapshot snapshot;
bool _liked = true;
static LikesModel of(BuildContext context) =>
ScopedModel.of<LikesModel>(context, rebuildOnChange: true);
bool isLiked() => _liked;
void pressed(){
_liked = !_liked;
notifyListeners();
}
void changeLikes() {
Firestore.instance
.collection("lanchonetes")
.document(snapshot.documentID)
.updateData({'likes': FieldValue.increment(_liked ? -1 : 1)});
}
}