flutter - 此参数在Flutter文档中传递给此回调函数的位置是什么?

标签 flutter dart callback

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/

相关文章:

flutter - 如何在 Flutter 中导入 intl 库?

firebase - 更新 map 字段-Flutter

Flutter:点击时底部导航栏上选定的图标不会改变

flutter - 使用onPressed Flutter刷新类(class)

c++ - FLTK C++ Callbakc 问题

unit-testing - 在 Dart 中,如何在单元测试中验证不抛出异常的 void 方法?

flutter - 如何使用回调方法获取 Flutter 中按钮的文本?

Flutter Objectbox如何修复 "Read Only File System"代码30?

Javascript:回调中的变量范围

c++ - sqlite3_exec() 回调函数说明