dart - Flutter:如何创建一行居中的单词,周围有一条线?

标签 dart flutter flutter-layout

尝试实现如下效果:

The word OR with 2 horizontal lines around it

这是我的代码:

            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 出现在中间但两个 Divider 都被隐藏了? (但是,如果我玩高度你可以看到行的高度增加/减少但仍然没有分隔线。我怎样才能得到这种效果?

最佳答案

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

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,
        ),
       ),
      ],
    );
   }
  }

关于dart - Flutter:如何创建一行居中的单词,周围有一条线?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53987953/

相关文章:

flutter - 如何在Android Studio中不运行模拟器/模拟器的情况下运行Dart程序

flutter - paint()方法中的Size属性不同于CustomPainter中指定的大小

flutter - 如何解决 Flutter 中的不可空错误?

flutter - 向下滚动时隐藏底部导航栏,反之亦然

dart - 使用flutter,如何做基于角色的认证?

firebase - 如果应用程序已经在运行,Flutter 如何获取 firebase 动态链接?

android - 为什么我的小部件的构建方法认为我返回 NULL?

ios - 推特登录异常 flutter

flutter - 在BoxDecoration图像上强制裁剪

flutter - 如何对齐 TextFields 例如列中的文本()?