我有一个输入框和一个表,用于显示名称,我的代码如下:
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))
]),
],
)
],
),
),
当用户单击添加图标时,我希望能够动态更改并在表中显示数据