嘿,我要通过Github在这里添加代码
https://gist.github.com/vksBhardwaj/b4be173ef3299360311d542e55ca23b6
答案 0 :(得分:0)
您可以只在适配器的构造函数中传递值。在dart中,您还可以传递函数引用。然后,在您的网格项目的单击上调用您的函数。
这将在您的主类中调用原始函数。
class YourAdapter extends StatelessWidget {
final Function onItemTap;
YourAdapter(
{
this.onItemTap
});
//do something like this on the onPressed of your item
IconButton(
icon: Icon(icon),
color: Colors.deepPurpleAccent,
onPressed: () {
//this is the method that you passed as the reference in the
constructor. It will call the original function.
onItemTap(x,y);
},
)
}
我希望能有所帮助。