【问题标题】:can't set border radius on one side and border on one side flutter无法在一侧设置边框半径和一侧的边框颤动
【发布时间】:2021-06-17 03:55:51
【问题描述】:

为什么这段代码隐藏了容器的子容器以及如何解决这个问题。 我无法在一侧设置边框半径,在一侧或两侧设置边框

Container(
          child: Text(
            "Test",
            style: TextStyle(
              color: Theme.of(context).primaryColor,
              fontWeight: FontWeight.w800,
              fontFamily: "GE",
              fontSize: 30.0,
            ),
          ),
          width: double.infinity,
          height: 100.0,
          padding: EdgeInsets.symmetric(vertical: 100.0, horizontal: 100.0),
          decoration: BoxDecoration(
            color: Colors.grey[800],
            borderRadius: const BorderRadius.only(
              bottomLeft: const Radius.circular(50.0),
            ),
            border: Border(
              top:
                  BorderSide(width: 16.0, color: Colors.lightBlue.shade600),
              bottom:
                  BorderSide(width: 16.0, color: Colors.lightBlue.shade900),
            ),
          ),
        )

【问题讨论】:

    标签: flutter border border-radius


    【解决方案1】:

    因为垂直填充与容器的高度相同,因此没有空间让文本显示出来。

    您要么需要减少内边距,要么需要增加容器高度。

    === 根据评论更新:

    您不能同时添加 borderborderRadius,因此您会收到错误消息。

    由于您似乎只想在底部和顶部添加颜色,因此您可以使用 boxShadowborderRadius

    decoration: BoxDecoration(
      color: Colors.grey[800],
      borderRadius: const BorderRadius.only(
        bottomLeft: const Radius.circular(50.0),
      ),
      boxShadow: [
        BoxShadow(color: Colors.lightBlue.shade900, spreadRadius: 3),
      ],
    ),
    
    

    如果您希望顶部的颜色与底部的颜色不同,则必须解决此问题。解决这个问题的一种方法是抵消阴影,使其仅用作底部边框颜色。然后将 Container 包裹在一个 Column 中,并在其上方添加另一个薄 Container 作为顶部边框颜色,例如:

    Column(
      children: [
        // top border color
        Container(
          height: 5.0,
          color: Colors.lightBlue.shade600,
        ),
        Container(
          child: Text(
            "Test",
            style: TextStyle(
              color: Theme.of(context).primaryColor,
              fontWeight: FontWeight.w800,
              fontFamily: "GE",
              fontSize: 30.0,
            ),
          ),
          width: double.infinity,
          height: 100.0,
          decoration: BoxDecoration(
            color: Colors.grey[800],
            borderRadius: const BorderRadius.only(
              bottomLeft: const Radius.circular(50.0),
            ),
            boxShadow: [
              BoxShadow(
                color: Colors.lightBlue.shade900,
                spreadRadius: 3,
                // offset to act as bottom border color
                offset: Offset(0, 5),
              ),
            ],
          ),
        ),
      ],
    ),
    
    

    【讨论】:

    • 我删除了填充,但实际上我说的问题是当我删除边界半径时它解决了,边界半径一侧和一侧或两侧边界的组合问题
    • @ĀĥmêdŴǻlêd 您是否在调试控制台中收到任何错误消息?如果是这样,请将它们发布在问题中。
    • 渲染库捕获的异常在paint() 期间抛出了以下断言:只能为统一边框指定borderRadius。以下不统一: BorderSide.color BorderSide.width BorderSide.style 相关的导致错误的小部件是 Container lib\widgets\header.dart:8 抛出异常时,这是堆栈#0 Border.paint. #1 Border.paint #2 _BoxDecorationPainter.paint #3 RenderDecoratedBox.paint #4 RenderObject._paintWithContext
    • 触发异常时正在处理以下 RenderObject:RenderDecoratedBox#d5c3f RenderObject:RenderDecoratedBox#d5c3f parentData:(可以使用大小)约束:BoxConstraints(w=480.0, h=100.0) size: Size(480.0, 100.0) 装饰: BoxDecoration 颜色: Color(0xff424242) 边框: Border(top: BorderSide(Color(0xff039be5), 16.0, BorderStyle.solid), 底部: BorderSide(Color(0xff01579b), 16.0, BorderStyle。实心))borderRadius:BorderRadius.only(bottomLeft:Radius.circular(50.0))
    • 配置:ImageConfiguration(bundle: PlatformAssetBundle#913ef(), devicePixelRatio: 1.0, locale: en_US, textDirection: TextDirection.ltr, platform: android) child: RenderPadding#763ac NEEDS-PAINT parentData: (可以使用大小)约束:BoxConstraints(w=480.0, h=100.0)
    猜你喜欢
    • 1970-01-01
    • 2019-07-06
    • 1970-01-01
    • 1970-01-01
    • 2013-03-02
    • 2012-06-29
    • 1970-01-01
    • 1970-01-01
    • 2017-11-26
    相关资源
    最近更新 更多