android 如何在Flutter中的列上的Widget之间添加垂直分隔符?

js81xvg6  于 2023-06-20  发布在  Android
关注(0)|答案(7)|浏览(132)

祝你愉快
我已经在这个网站上冲浪关于如何添加一个垂直分隔符之间的小部件列在Flutter?但我一无所获
我想要的

我已经做了水平分割线。但是当我试图做一个垂直的分隔线来分隔两个对象(文本|(图片)我什么都没得到。
代码如下:

Row(children: <Widget>[
                Expanded(
                  child: new Container(
                      margin: const EdgeInsets.only(left: 10.0, right: 20.0),
                      child: Divider(
                        color: Colors.black,
                        height: 36,
                      )),
                ),
                Text("OR"),
                Expanded(
                  child: new Container(
                      margin: const EdgeInsets.only(left: 20.0, right: 10.0),
                      child: Divider(
                        color: Colors.black,
                        height: 36,
                      )),
                ),
              ]),

上面的代码是水平的

Row(
          mainAxisAlignment: MainAxisAlignment.spaceEvenly,
          children: <Widget>[
            Row(
              children: <Widget>[
                Image.asset('images/makanan.png', width: 30,),
                Text('Diskon 20%', style: TextStyle(fontSize: 5, color: Colors.green),)
              ],
            ),
            VerticalDivider(
              color: Colors.red,
              width: 20,
            ),
            Row(
              children: <Widget>[
                Image.asset('images/makanan.png', width: 30,),
                Text('Diskon 20%', style: TextStyle(fontSize: 5, color: Colors.green),)
              ],
            ),
          ],
        ),

上面的代码我做垂直分割。但失败了
需要你的帮助,谢谢。

q8l4jmvw

q8l4jmvw1#

尝试替换

VerticalDivider(color: Colors.red, width: 20)

Container(height: 80, child: VerticalDivider(color: Colors.red))
9udxz4iz

9udxz4iz2#

试试这个:

IntrinsicHeight(
    child: new Row(
  mainAxisAlignment: MainAxisAlignment.spaceEvenly,
  children: <Widget>[
    Text('Foo'),
    VerticalDivider(),
    Text('Bar'),
    VerticalDivider(),
    Text('Baz'),
  ],
))
wwwo4jvm

wwwo4jvm3#

你可以使用

VerticalDivider(
thickness: 1,
color:Colors.black
            
),

Container(
height: 30,
width: 1,
color: Colors.black

)
3xiyfsfu

3xiyfsfu4#

这里是答案。
对我很有效。感谢@Android团队先生和@sunxs先生的帮助:)

Row(
          mainAxisAlignment: MainAxisAlignment.spaceEvenly,
          children: <Widget>[
            Row(
              children: <Widget>[
                Image.asset('images/makanan.png', width: 30,),
                Text('Diskon 20%', style: TextStyle(fontSize: 5, color: Colors.green),)
              ],
            ),
            Container(height: 80, child: VerticalDivider(color: Colors.red)),
            Row(
              children: <Widget>[
                Image.asset('images/makanan.png', width: 30,),
                Text('Diskon 20%', style: TextStyle(fontSize: 5, color: Colors.green),)
              ],
            ),
            Container(height: 80, child: VerticalDivider(color: Colors.red)),
            Row(
              children: <Widget>[
                Image.asset('images/makanan.png', width: 30,),
                Text('Diskon 20%', style: TextStyle(fontSize: 5, color: Colors.green),)
              ],
            ),
          ],
        ),
ulydmbyx

ulydmbyx5#

最佳的方法是将垂直分隔器放在SizedBox中。

SizedBox(
 height: 80, 
 child: VerticalDivider(color: primaryColor),
)
fbcarpbf

fbcarpbf6#

您可以尝试:

Container(
  color: Colors.grey,
  height: 30,
  width: 1,
),

对我很有效!:))

myzjeezk

myzjeezk7#

VerticalDivider(
       color: Colors.white,
       width: 1.0,
),

Demo

相关问题