Flutter 文档中这个回调函数的这个参数是在哪里传递的?
Where is this parameter passed to this callback function in Flutter documentation?
Where/How 是 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 并将回调传递给构造函数。 MyListItem 可能会在它被点击时在内部使用回调并将 Item 传递给回调
MyListItem
是一个以 Function(Item item)
作为参数的函数。您没有为 MyListItem
传递参数项目,该项目将由 MyListItem
内部提供。它唯一需要作为参数的是一个 函数,该函数将 Item 项目 作为参数。
Where/How 是 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 并将回调传递给构造函数。 MyListItem 可能会在它被点击时在内部使用回调并将 Item 传递给回调
MyListItem
是一个以 Function(Item item)
作为参数的函数。您没有为 MyListItem
传递参数项目,该项目将由 MyListItem
内部提供。它唯一需要作为参数的是一个 函数,该函数将 Item 项目 作为参数。