The full error is :
Unhandled Exception: setState() called after dispose(): FormState#416d6(lifecycle state: defunct, not mounted)
E/flutter ( 4898): This error happens if you call setState() on a State object for a widget that no longer appears in the widget tree (e.g., whose parent widget no longer includes the widget in its build). This error can occur when code calls setState() from a timer or an animation callback.
Looking at other answers on Stack, I added a check if(!mounted)return;
but it didn't do anything.
My code where I am having issue is :
FlatButton(
onPressed: () async {
if (!mounted) return;
setState(() {
isLoading = true;
});
await saveSignUpData();
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => Home()));
isLoading = false;
},
child: Center(
child: Text("Continue",
style:
Theme.of(context).textTheme.button),
),
),
If I remove setState, my code is working fine but with setState I am getting the aforementioned error and this is the only place where I am using setState.
saveSignUpData function is just signing up the user with the help of NodeJS.
question from:
https://stackoverflow.com/questions/65925502/flutter-setstate-not-working-unhandled-exception-setstate-called-after-dis 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…