如何在颤动表中显示用户输入

时间:2019-11-30 20:40:22

标签: flutter

我有一个输入框和一个表,用于显示名称,我的代码如下:

Container(
        color: Color(0xff343434),
        child: Column(
          children: <Widget>[
            Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget> [
                Container(
                  margin: EdgeInsets.fromLTRB(MediaQuery.of(context).size.width * 0.1, 10, 0, 10),
                  width: MediaQuery.of(context).size.width * 0.40,
                  child: TextField(
                    controller: _textFieldController,
                    onChanged: (text) => playerName = text,
                    decoration: InputDecoration(
                      hintMaxLines: 1,
                      hintText: "Playername"
                    ),
                  ),
                ),
                IconButton(
                  icon: Icon(Icons.add),
                  color: Color(0xff1D1D1D),
                  onPressed: () {playerName.length > 0 ? playerNames.add(playerName) : print("Tomt"); playerName = ""; _textFieldController.clear();})
              ]
            ),
            Table(
              defaultColumnWidth: FractionColumnWidth(1/3),
              defaultVerticalAlignment: TableCellVerticalAlignment.middle,
              children: [
                for(var x = 0; x < playerNames.length; x += 3)
                  TableRow( children: [
                    for(var y in playerNames)
                      Center(child:Text(y))
                  ]),
              ],
            )
          ],
        ),
      ),

当用户单击添加图标时,我希望能够动态更改并在表中显示数据

1 个答案:

答案 0 :(得分:0)

所有这些都必须包含在Timestamp中,并且您的按下的代码应包含setState()

请参阅示例和StatefulWidget