myTapCallback()
的参数在哪里/如何传递给MyListItem(myTapCallback)
调用?
@override
Widget build(BuildContext context) {
return SomeWidget(
// Construct the widget, passing it a reference to the method above.
MyListItem(myTapCallback), //<—- where is item?
);
}
void myTapCallback(Item item) {
print('user tapped on $item');
}
资料来源:https://flutter.dev/docs/development/data-and-backend/state-mgmt/simple
最佳答案
MyListItem
是将Function(Item item)
作为参数的函数。您没有传递MyListItem
的参数项目,该项目将由MyListItem
内部提供。它唯一需要作为参数的是函数,该函数将Item项作为参数。
关于flutter - 此参数在Flutter文档中传递给此回调函数的位置是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62523303/