【问题标题】:children centered in a row孩子们排成一排
【发布时间】:2019-03-19 05:50:15
【问题描述】:

我正在使用 Align Widget 将子项集中在一行中,但它不起作用...我做错了什么?

这是代码:

.... 主页.dart ....

@override 
Widget build(BuildContext context){
_context = context;

return new Scaffold(
    appBar: new AppBar(title: Text("MiniCon")),

    body: new Container(child: new Column(children:[
    new Align(alignment:Alignment.center,child:new Row(children:[
    _commons.makeEditText("Ahorro Real", grey, false),
    _commons.makeEditText("Ahorro Actual", black, true),
    _commons.makeEditText("Gastos", black, true)
  ])),


  new Row(children:[
    _commons.makeEditText("Ahorro Real", grey, false)
  ])
  ])));
}

.... _commons.dart ....

Widget makeEditText(String label, Color labelColor, bool enabled) {
return 
new Padding(padding:EdgeInsets.all(2.5), child:
new Container(decoration: 
new BoxDecoration(border: 
new Border.all(width:2.0)),padding: new 
new EdgeInsets.all(10.0),width:110.0,child:
new TextField(enabled: enabled,
  style: TextStyle(color: labelColor),
  decoration: new InputDecoration(
      labelStyle: TextStyle(fontSize: 15.0), labelText: label),
)));
}

提前致谢!!

【问题讨论】:

    标签: widget flutter row


    【解决方案1】:

    这使行居中:

    body: Container(
            child: Column(children: [
              Row(mainAxisAlignment: MainAxisAlignment.center, children: [
                makeEditText("Ahorro Real", Colors.grey, false),
                makeEditText("Ahorro Actual", Colors.black, true),
                makeEditText("Gastos", Colors.green, true)
              ]),
              new Row(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: [makeEditText("Ahorro Real", Colors.red, false)])
            ]),
          ),
    

    【讨论】:

    • 乐于助人! @PabloLanzaMoreno
    【解决方案2】:

    请改用 Column/Row 小部件的 mainAxisAlignment / crossAxisAlignment 属性。

    【讨论】:

      猜你喜欢
      • 2011-11-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-16
      • 2021-08-03
      • 2011-02-04
      • 2014-11-21
      相关资源
      最近更新 更多