i am trying to navigate from one page to another but when i try to call a particular value (stuff), it shows me this error, even though in this case both the argument type and the parameter type are the same
class ProductList extends StatelessWidget {
final List<Map<String, dynamic>> stuff;
final Function addProduct;
final Function updateProduct;
const ProductList(
this.stuff, this.addProduct, this.updateProduct, {
Key? key,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return ListView.builder(
itemBuilder: (BuildContext context, int index) {
return ListTile(
leading: Image.asset(stuff[index]['image']),
title: Text(stuff[index]['title']),
trailing: IconButton(
icon: Icon(Icons.edit),
onPressed: (){
Navigator.of(context).push(
MaterialPageRoute(builder: (BuildContext context) {
return ProductCreate(stuff: stuff[index], addProduct: addProduct, updateProduct: updateProduct ,);
})
);
},
),
);
},
itemCount: stuff.length,
);
}
}
Down below is the productCreate
class ProductCreate extends StatefulWidget {
final Function addProduct;
final Function updateProduct;
final List <Map<String, dynamic>> stuff;
ProductCreate({required this.addProduct, required this.stuff, required this.updateProduct});
@override
State<ProductCreate> createState() => _ProductCreateState();
}
as said, when i tried calling stuff while navigating to the productCreate, it flags that error. im pretty new to flutter so maybe there is something im missing. help would be really appreciated
2
Answers
Im not really sure what a you trying to do. But if you only want to pass a single item to
ProductCreate
, then try below code.Because you only send single item to
ProductCreate
but the parameter atProductCreate
set tolist
type.you are sending the single item of stuff in the ProductCreate class .. so you just send stuff not stuff[index]