Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

312
Visualizações
Is there a way to test an AppLifecycleState change in a Flutter unit test?

My app writes user preferences to a local file when the app is moved to the background (AppLifecycleState.paused) and I'd like to write a test for this behavior.

Is there a way to mimic this in a unit test? Or is this something that would need to be done as an integration test?

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

You can call binding.handleAppLifecycleStateChanged to fake the app going in and out of the foreground in a unit test.

over 4 years ago · Santiago Trujillo Relatório

0

tester.binding.handleAppLifecycleStateChanged is definitly the correct way to test it.

ex: Statefull widget on the home page that listen to app lifecycle

  @override
  void didChangeAppLifecycleState(AppLifecycleState state) {
    if (state == AppLifecycleState.paused) {
      pushLoginPage(context);
    }
  }

If you want to test this, you have to paused first, and then resumed to ensure Flutter navigation.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda