Flutter小部件对齐

问题描述 投票:0回答:1

我想将(+,-)图标和TextField对准相同的Vertical位置。但是我不明白这一点。这是我的代码。

Row(
    crossAxisAlignment: CrossAxisAlignment.center,
    children: <Widget>[
             InkWell(
                  child: Icon(Icons.remove ,color: Colors.white),
                  onTap: (){},
                     ),
                     Container(
                               width: 35,
                               height: 40,
                               child: TextField(
                                      inputFormatters:[WhitelistingTextInputFormatter(RegExp(digit_Reg_Expression))],
                                      keyboardType: TextInputType.number,
                                      textAlign: TextAlign.center,
                                      cursorColor: Colors.green,
                                      controller: Controler_size[index],
                                               ),
                              ),
                                      InkWell(
                                              child: Icon(Icons.add,color: Colors.white),
                                              onTap: (){},
                                             )
                      ],
)

请帮助我将这些Widgets垂直放置,以便它们在相同的垂直位置对齐。enter image description here

flutter flutter-layout
1个回答
0
投票

如果要放置元素vertically,请使用Column小部件。如果要放置元素horizontally,请使用Row小部件。

检查下面的代码:效果很好:

Column(
    crossAxisAlignment: CrossAxisAlignment.center,
    children: <Widget>[
             InkWell(
                  child: Icon(Icons.remove ,color: Colors.white),
                  onTap: (){},
                     ),
                     Container(
                               width: 35,
                               height: 40,
                               child: TextField(
                                      inputFormatters:[WhitelistingTextInputFormatter(RegExp(digit_Reg_Expression))],
                                      keyboardType: TextInputType.number,
                                      textAlign: TextAlign.center,
                                      cursorColor: Colors.green,
                                      controller: Controler_size[index],
                                               ),
                              ),
                                      InkWell(
                                              child: Icon(Icons.add,color: Colors.white),
                                              onTap: (){},
                                             )
                      ],
)

我希望这会有所帮助。

© www.soinside.com 2019 - 2024. All rights reserved.