1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

  2. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Flutter] I have proble with "context" in my GestureDetectore?

Discussão em 'Mobile' iniciado por Stack, Setembro 27, 2021.

  1. Stack

    Stack Membro Participativo

    i want redirect my application when i pressed one of my colum, but i have a erroe in the onPressed() (): {Navigator.push () the "context" is not defined. but i dont know how pass context.

    maybe the solutions is easy but this is my first time working with flutter

    The mthod onPressed is in the first GestureDetectore().

    class ProductDataGridSource extends DataGridSource {
    ProductDataGridSource(this.productList) {
    buildDataGridRow();
    }
    late List<DataGridRow> dataGridRows;
    late List<Product> productList;

    @override
    DataGridRowAdapter? buildRow(DataGridRow row) {
    return DataGridRowAdapter(cells: [
    GestureDetector(
    child: TextButton(
    style: TextButton.styleFrom(
    primary: Colors.blue,
    onSurface: Colors.blueAccent,
    ),
    onPressed: (){
    Navigator.push(
    context,
    MaterialPageRoute(builder: (context) => const SecondRoute()),
    },
    child: Text(row.getCells()[0].value.toString()),
    ),
    ),
    GestureDetector(
    onTap: (){
    print(row.getCells()[1].value.toString());
    },
    child: TextButton(
    style: TextButton.styleFrom(
    primary: Colors.blue,
    onSurface: Colors.red,
    ),
    onPressed: null,
    child: Text(row.getCells()[1].value.toString()),
    ),
    ),

    ]);
    }

    Continue reading...

Compartilhe esta Página