简体   繁体   English

flutter ListView - 如何同时左右对齐?

[英]flutter ListView - How do I align left and right at the same time?

I have a ListView of items.我有一个项目的 ListView。 I want to put a name on the left and a value on the right.我想在左边放一个名字,在右边放一个值。 unable to figure out a way to do this so that they're both aligned to the edge:无法找到一种方法来做到这一点,以便它们都与边缘对齐:

        ...
        ListView(
          shrinkWrap: true,
          padding: EdgeInsets.all(15.0),
          children: <Widget>[
            Text(
              'Asset 0 <-  -> Balance',
              style: TextStyle(
                fontSize: 18.0,
                color: Colors.grey[850],
              ),
            ),
            Text(
              'Asset 1 <-  -> Balance',
              style: TextStyle(
                fontSize: 18.0,
                color: Colors.grey[850],
              ),
            ),
            Text(
              'Asset 2 <-  -> Balance',
              style: TextStyle(
                fontSize: 18.0,
                color: Colors.grey[850],
              ),
            ),
          ]
        ),
        ...

左对齐

(I want the balance on the right and the asset name on the left) (我想要右边的余额和左边的资产名称)

Is there, perhaps a special widget just for this purpose?是否有专门用于此目的的特殊小部件? I want it to be scrollable like a ListView and I want it to scroll together of course.我希望它像 ListView 一样可滚动,当然我希望它一起滚动。 It'd be cool if the row had an alignment option called edges that aligns two items in the row to each side respectively.如果该行有一个称为边缘的对齐选项,可以将行中的两个项目分别对齐到每一侧,那就太酷了。 but I don't think that exists.但我认为这不存在。 What's the common solution for this issue?这个问题的通用解决方案是什么?

use this:用这个:

row(
children:[
mainAxisAlignment:MainAxisAlignment.spaceBetween;
Text(
              'Asset 0',
              style: TextStyle(
                fontSize: 18.0,
                color: Colors.grey[850],
              ),
            ),
Text(
              'Balance',
              style: TextStyle(
                fontSize: 18.0,
                color: Colors.grey[850],
              ),
            ),
]
)

An alternative approach to do the same when the Row is with multiple widgets is to add Spacer() between the Row childrenRow有多个小部件时,另一种方法是在Row children之间添加Spacer()

Sample Code示例代码

Row(children: [
      Text(
        'Asset 0',
        style: TextStyle(
          fontSize: 18.0,
          color: Colors.grey[850],
        ),
      ),
      Spacer(),
      Text(
        'Balance',
        style: TextStyle(
          fontSize: 18.0,
          color: Colors.grey[850],
        ),
      ),
    ])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM