【问题标题】:Spacebetween container in a Row not working连续容器之间的空间不起作用
【发布时间】:2021-08-20 02:20:58
【问题描述】:

基本上,我正在尝试使用以下代码在 2 个容器之间放置一个空格,因此每个 But mainAxisAlignment 小部件都不起作用。两个容器在开始时相互粘在一起

Positioned(
                  bottom: 10,
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: <Widget>[                   
                      Container(
                          decoration: BoxDecoration(
                          child: Padding(
                              padding: EdgeInsets.all(5.0),
                              child: Text(product.name,
                                  style: TextStyle(
                                      color: Colors.white,
                                      fontSize: 18.0,
                                      fontWeight: FontWeight.w300)))),

                      Container(
                          decoration: BoxDecoration(
                              color: Colors.white,
                              border: Border.all(color: Colors.white),
                              borderRadius: BorderRadius.circular(5.0)),
                          child: Padding(
                              padding: EdgeInsets.all(5.0),
                              child: Text(
                                  '${PriceConverter.convertPrice(context, _startingPrice, discount: product.discount, discountType: product.discountType, asFixed: 1)}'
                                  '${_endingPrice != null ? ' - ${PriceConverter.convertPrice(context, _endingPrice, discount: product.discount, discountType: product.discountType, asFixed: 1)}' : ''}',
                                  style: TextStyle(
                                      fontSize: 18.0,
                                      fontWeight: FontWeight.normal))))
                    ],
                  )
                  ),

【问题讨论】:

  • 容器是否填满了行?此外,添加空间的一种简单方法是将容器包装在 Padding 小部件中或在容器之间插入 SizedBox(width:10.0)

标签: flutter


【解决方案1】:

只需为定位的小部件分配宽度

见下文

 Positioned(
     width: MediaQuery.of(context).size.width, // <- Add this line (width == screen_width)
     bottom: 10,
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: <Widget>[
                   // widget 1
                   // widget 2
                 ]
 );

【讨论】:

  • 谢谢伙计,正是我想要的样子。
猜你喜欢
  • 2017-01-18
  • 1970-01-01
  • 1970-01-01
  • 2017-09-21
  • 1970-01-01
  • 2019-12-17
  • 2020-01-17
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多