Im creating an app thats making reservations for boat rentals, but i struggle to fix this problem any1 can help?
Providing code samples:
if (docs.size == 0) {
reservations.doc(resID).set({
'resID': resID,
'name': name,
"surname": surname,
"phoneNumber": phoneNumber,
"rental": ProductCardInCart.rental,
'boat': ProductCardInCart.boat,
'date': date,
'time': time
}).then((value) {
print("Reservation made");
setState(() {
Body.empty = true;
});
}).catchError((error) => print("Failed to reservate: $error"));
} else if (docs.size != 0) {
setState(() {
Body.empty = false;
});
print('jestjus');
}
});
} else {
return;
}
});
}
}
this setstate is working well
.then((value) {
print("Reservation made");
setState(() {
Body.empty = true;
});
but this one isnt and its throwing exception
} else if (docs.size != 0) {
setState(() {
Body.empty = false;
});
print('jestjus');
}
Error that its throwing:
7980): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: setState() called in constructor: ReservationMakingState#861c9(lifecycle state: created, no widget, not mounted)
E/flutter ( 7980): This happens when you call setState() on a State object for a widget that hasn't been inserted into the widget tree yet. It is not necessary to call setState() in the constructor, since the state is already assumed to be dirty when it is initially created.
Thanks for help in advance
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…