繁体   English   中英

Flutter CheckboxListTile辅助小部件功能

[英]Flutter CheckboxListTile secondary widget function

使用带有编辑图标的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);
      },
    );
  }

可能会有更好的方法。 但是,对实现方法的简要说明如下:

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(),
      );
  }

这将导致弄成这样

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM