如何在 Flutter 中连接不同的 Stateful Widget
How to Make Connection Between Different Stateful Widgets in Flutter
嘿,我在这里通过 Github
添加我的代码
https://gist.github.com/vksBhardwaj/b4be173ef3299360311d542e55ca23b6
您可以只在适配器的构造函数中传递值。在 dart 中,您还可以传递函数引用。然后在单击您的网格项时调用您的函数。
这将调用主程序中的原始函数 class。
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);
},
)
}
希望对您有所帮助。
嘿,我在这里通过 Github
添加我的代码https://gist.github.com/vksBhardwaj/b4be173ef3299360311d542e55ca23b6
您可以只在适配器的构造函数中传递值。在 dart 中,您还可以传递函数引用。然后在单击您的网格项时调用您的函数。
这将调用主程序中的原始函数 class。
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);
},
)
}
希望对您有所帮助。