首页 > 解决方案 > Flutter:如何创建一个居中单词的行,周围有一条线?

问题描述

试图完成以下效果:

单词 OR 周围有 2 条水平线

这是我的代码:

            new Row(
                mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                mainAxisSize: MainAxisSize.max,
                crossAxisAlignment: CrossAxisAlignment.center,
                children: <Widget>[
                  const Divider(
                      color: const Color(0xFF000000),
                      height: 20
                  ),
                  new Text(
                    "OR",
                    style: new TextStyle(
                      fontSize: 20.0,
                      color: const Color(0xFF000000),
                      fontWeight: FontWeight.w200,
                    ),
                  ),
                  const Divider(
                      color: const Color(0xFF000000),
                      height: 20
                  ),
                ]),

单词 OR 出现在中间,但两个 Dividers 都隐藏了?(但是,如果我玩高度,你可以看到行的高度增加/减少但仍然没有分隔线。我怎样才能得到这个效果?

标签: dartflutterflutter-layout

解决方案


使用这个小部件,它会做你想要的

class OrComponent extends StatelessWidget {


   @override
   Widget build(BuildContext context) {

      return Row(
         children: <Widget>[
           Expanded(
             child: Container(
               height: 2.0,
               color: AppColor.lighterGrey,
             ),
           ),
        Container(
           margin: EdgeInsets.symmetric(horizontal: 3.0),
           child: Text("OR",style:TextStyle(color:Colors.black)),
        ),
        Expanded(
           child: Container(
             height: 2.0,
             color: Colors.grey,
        ),
       ),
      ],
    );
   }
  }

推荐阅读