I got this error when I try to pass the onPressed value from a variable inside list of items .
class Raccourcis {
final String imgSrc, title;
final Function() onTapAction;
BuildContext context;
Raccourcis({this.imgSrc, this.title, this.onTapAction, this.context, info});
}
List listeRaccourcis = [
Raccourcis(
title: "Ajouter Un Bon de commande",
imgSrc: "assets/images/commande.png",
onTapAction: () {
print("Passed");
BuildContext context;
Navigator.push(
context,
MaterialPageRoute(builder: (context) => Test()),
);
}),
];
and this is how I'm willing to use my list in another stageful Widgetand the onPressed values.
child: MaterialButton(
onPressed: widget.info.onTapAction,
In the console I'm getting this error :
TypeError: Cannot read properties of null (reading 'findAncestorStateOfType')