I have a widget with this method in flutter that is called by two different screens, I would like ‘Navigator.pop’ to change its behavior depending on which screen calls it.
On the first screen it would apply a common ‘pop’, and on the second screen, for a specific route. Can you help me with this?
`
void salvarCartao(InputCartaoDto cartao, BuildContext context) async {
var cartaoDto = await AdicionarCartaoCommand().execute(cartao, context);
if (cartaoDto != null) {
var usuarioCorrente = await ObterUsuarioCorrenteCommand().execute();
var listaCartoes = usuarioCorrente?.cartoes;
listaCartoes?.add(cartaoDto);
AtualizarUsuarioCommand().execute(usuarioCorrente!);
}
//if screen 1 called the method:
Navigator.pop(context);
//if screen 2:
Navigator.popUntil(context, ModalRoute.withName('/carrinho-pagamento'));
}
`
I’m actually still learning flutter, I couldn’t think of a solution with my current knowledge
2
Answers
then redefine your function. Ex:
You can pass a flag to the salvarCartao function, depending on which screen calls it.
or