【问题标题】:Flutter CheckboxListTile secondary widget functionFlutter CheckboxListTile 辅助小部件功能
【发布时间】:2019-05-29 20:46:12
【问题描述】:

使用带有编辑图标的 CheckboxListTile 小部件作为辅助小部件。

我希望能够编辑复选框列表中的每个项目。

!(https://ibb.co/m0Gc3Gx)

添加一个能够编辑 CheckboxListTile 中每个项目的函数的好方法是什么。

 Widget _buildItem(BuildContext context, int index) {
    final remind = reminders[index];

    return CheckboxListTile(
      value: remind.isDone,
      title: Text(remind.title + "-" + remind.message),
      secondary: const Icon(Icons.edit),
      controlAffinity: ListTileControlAffinity.leading,
      onChanged: (bool isChecked) {
        onRemindToggle(remind, isChecked);
      },
    );
  }

【问题讨论】:

  • “将辅助小部件连接到功能”是什么意思?你能详细说明一下吗?
  • 谢谢约翰,我更新了描述,希望现在更有意义。

标签: flutter


【解决方案1】:

可能有更好的方法来做到这一点。但简单介绍一下如何实现如下:

static String name = "John";

  Map<String, bool> values = {
    name: true,
  };

  Widget checkbox()
  {
    return ListView(
        children: values.keys.map((String key) {
          return new CheckboxListTile(
            title: new Text(name),
            value: values[key],
            secondary: IconButton(
              icon: Icon(Icons.edit),
              onPressed: (){
                setState(() {
                  name = "James";                                  
                });
                print("Name is : $name");
              },
            ),
            controlAffinity: ListTileControlAffinity.leading,
            onChanged: (bool value) {
              setState(() {
                values[key] = value;
              });
            },
          );
        }).toList(),
      );
  }

这将导致类似于this

当按下编辑图标时,字段从 john 变为 James。同样,您可以根据需要编辑代码。 希望它有所帮助:)

【讨论】:

  • 感谢约翰,这帮助我找到了正确的方向。
猜你喜欢
  • 2020-12-25
  • 2021-12-10
  • 1970-01-01
  • 1970-01-01
  • 2019-01-23
  • 2016-06-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多