setState junto com uma sobrescrita dispose. #146
Unanswered
namikazefabi
asked this question in
Perguntas e Respostas
Replies: 1 comment
-
Bom dia @namikazefabi, tu não deve usar um setState dentro de um dispose e também o super.dispose tem que ser o ultimo método chamado dentro do dispose.
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Preciso utilizar um esse método ===>
" Future getResumoDiario(String tipoRetorno, String inicio, String fim) async {
await API.getResumoDiarioGeral(tipoRetorno, inicio, fim);
setState(() {});
}",
dentro da minha da minha sobrescrita dispose ===> "
@OverRide
void dispose() async {
super.dispose();
await getResumoDiario(
'R',
DateTime.parse(DateFormat('yyyy-MM-dd')
.format(DateFormat('dd/MM/yyyy').parse(ctrDtInicio.text)))
.toString(),
DateTime.parse(DateFormat('yyyy-MM-dd')
.format(DateFormat('dd/MM/yyyy').parse(ctrDtFim.text)))
.toString());
}",
porem ocorre esse erro quando utilizo o setState dentro do método : "FlutterError (setState() called after dispose(): _ConsultaKardexState#7de66(lifecycle state: defunct, not mounted) 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. The preferred solution is to cancel the timer or stop listening to the animation in the dispose() callback. Another solution is to check the "mounted" property of this object before calling setState() to ensure the object is still in the tree. This error might indicate a memory leak if setState() is being called because another object is retaining a reference to this State object after it has been removed from the tree. To avoid memory leaks, consider breaking the reference to this object during dispose().)".
Preciso do setState no metodo para atualizar uma lista no retorno de uma outra tela, como posso fazer para atualizar essa lista no retorno da tela?, caso aja outra maneira de fazer esse retorno na tela atualizando minha lista fico agradecido pelas dicas.
Beta Was this translation helpful? Give feedback.
All reactions