Flutter如何在ListTile中使用文本字段?

时间:2018-05-30 14:31:46

标签: layout dart tableview textfield flutter

我想实现一个ListTile,它在尾部是一个文本字段,这就像iOS静态tableview,这样用户可以点击它并直接编辑文本。 无论如何,如何在Flutter中做到这一点?

2 个答案:

答案 0 :(得分:5)

好吧,stackoverflow人总是不想回答问题。对于未来人们也可能有这个麻烦,这是解决方案:

new ListTile(
        title: Text('签名'),
        trailing: new Container(
          width: 150.0,
          child: new Row(
            mainAxisAlignment: MainAxisAlignment.end,
            children: <Widget>[
              new Expanded(
                flex: 3,
                child: new TextField(
                  textAlign: TextAlign.end,
                decoration:
                    new InputDecoration.collapsed(hintText: '$userAddr'),
              ),
              ),
              new Expanded(
                child: new IconButton(
                icon: new Icon(Icons.chevron_right),
                color: Colors.black26,
                onPressed: () {},
              ),
              )
            ],
          ),
        ),
      ),

始终使用Expand for textfiled。

答案 1 :(得分:3)

现在,在Flutter V1.12上,您可以在标题中放入Row并填充

ListTile(
        title: Row(
          children: <Widget>[
            Expanded(
              child: Text('签名')
            ),
            Expanded(
              child: TextField(
                // your TextField's Content
              ),
            ),
          ],
        ),
        trailing: IconButton(
            icon: new Icon(Icons.chevron_right),
            color: Colors.black26,
            onPressed: () {},
          )
        ),
相关问题