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

131
Visualizações
GridView onTap is only called during creation

I made a GridView with children that each has a GestureDetector and a onTap method set. But the onTap event gets called only when the view is created and not when the item has been tapped. What am I doing wrong here?

class MyGridView extends StatelessWidget {

  @override
  Widget build(BuildContext context) {
    return new Column(
        children: <Widget>[
          new Expanded(
              child: new GridView.count(
                  crossAxisCount: 2,
                  children: [
                    new GridItem(0),
                    new GridItem(1)
                  ]
              )
          )
        ]
    );
  }
}

class GridItem extends StatelessWidget {
  final int code;
  GridItem(this.code);

  @override
  Widget build(BuildContext context) {
    return new GestureDetector(
        onTap: print(code),
        child: new Container(
            height: 48.0,
            child: new Text('$code')
        )
    );
  }
}
about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

You want:

onTap: () { print(code); },

What you're doing is calling print, then saving the return value from print (which will be a null) as the onTap handler, which actually disables the onTap handler. If you see anything in the logs it'll be from the time you actually did the build, not when you tapped.

about 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