使用 onDeleted 属性 移除 Flutter ChipWidget

Removing Flutter ChipWidget with onDeleted property

我是 Flutter 的新手,我在 Google 中找到了下面的示例代码来演示使用 sync* 和 yield 声明 Chip 小部件:

Iterable<Widget> get actorWidgets sync* {
     for (final Actor actor in _cast) {
      yield Padding(
        padding: const EdgeInsets.all(4.0),
        child: Chip(
             avatar: CircleAvatar(child: Text(actor.initials)),
             label: Text(actor.name),
             onDeleted: () {
              setState(() {
                 _cast.removeWhere((Actor entry) {
                   return entry.name == actor.name;
                 });
               });
             },
           ),
         );
       }
     }

我的问题可能与 sync* 和 yield 直接无关。

  1. 什么是'get'?
  2. removeWhere()如何获取参数'entry'?
  1. 得到的是Getter,class的每个实例都有,也可以根据需要修改。

  2. 这里Actor是具有各种属性的class,其中name也是一个属性。它必须从调用它的地方导入或声明在现有 class 中。

class 应该看起来像这样:

class Actor{
 String name;
 int age,
 // and many other properties

}

这是一篇不错的文章,可以了解更多信息:Dart Getters and Setters