How to pass two variables in a steless with Flutter

Asked

Viewed 127 times

0

Talk people! I’m starting on the flutter! Can you give me a light there? I take 'snapshot' from another screen with Navigator.of(context). push and on this screen Productscone need to pick up the json of the products with the apiProducts, but I’m lost here, on the other screen I did not catch anything else screen worked using the scheme below

class CategoriaTile extends StatelessWidget {

  final CategoryListModel snapshot;

  CategoriaTile(this.snapshot);

However on this screen as I have to declare the snapshot and the data of the apiProduct, the apiProduct is coming as null, how can I declare these two variables?

I tried this way, but to no avail

class ProdutoScreen extends StatelessWidget {

  final CategoryListModel snapshot;

  ListaProdutoData apiProduto;

  ProdutoScreen(this.snapshot){
    apiProduto = ListaProdutoData();
  }
  • What is a "steless"?? And I didn’t quite understand your question, do you want to pass two parameters in the constructor? Just do SuaClasse(this.snapshot, this.apiproduto) and declare the apiProduto as the end.

  • I was like,;
 final CategoryListModel snapshot;

 ListaProdutoData apiProduto;

 ProdutoScreen(this.snapshot, this.apiProduto);
 Error on other screen. 
Navigator.of(context).push(
 MaterialPageRoute(builder:
 (context)=>ProdutoScreen(snapshot))
 );
 
Compiler message:
lib/tiles/categoria_tile.dart:25:51: Error: Too few positional arguments: 2 required, 1 given.
 (context)=>ProdutoScreen(snapshot))


  • 1

    It was a problem in json, it was putting the wrong rating, it worked out your tip! Obg Matheus!

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.