ChatGPT解决这个技术问题 Extra ChatGPT

如何用颤动制作小部件的一侧圆形边框?

我正在尝试使用 Container 小部件在颤动中构建一侧圆形边框。我已经搜索过了,但找不到任何解决方案。

Container(
  width: 150.0,
  padding: const EdgeInsets.all(20.0),
  decoration: BoxDecoration(
    // borderRadius: BorderRadius.circular(30.0),
    /* border: Border(
      left: BorderSide()
    ),*/
  color: Colors.white
  ),
  child: Text("hello"),
),
不幸的是,到目前为止,您不能只塑造容器的一侧,但可以通过使该侧的两个角都具有圆形半径来实现类似类型的功能

B
Boken

使用 BorderRadius.only 并提供边

return Center(
  child: Container(
    height: 100,
    width: 100,
    decoration: BoxDecoration(
      borderRadius: BorderRadius.only(
        topRight: Radius.circular(40),
      ),
      border: Border.all(
        width: 3,
        color: Colors.green,
        style: BorderStyle.solid,
      ),
    ),
    child: Center(
      child: Text(
        "Hello",
      ),
    ),
  ),
);

输出

https://i.stack.imgur.com/XpU90.png


有没有办法只使用 ShapeBorder 实现?
B
Boken

您可以通过以下用于创建小部件的代码来实现此目的:

return Container(
  width: 150.0,
  padding: const EdgeInsets.all(20.0),
  decoration: BoxDecoration(
    shape: BoxShape.rectangle,
    color: Colors.white,
    borderRadius: BorderRadius.only(
      topLeft: Radius.circular(20.0),
      topRight: Radius.zero,
      bottomLeft: Radius.zero,
      bottomRight: Radius.zero,
    ),
  ),
  child: Text(
    "hello",
  ),
);

这样你就可以让你的左上角圆形边框与 Container 小部件一起颤动。


尝试添加代码的输出。查看您和另一个投票最高的答案之间的区别,主要区别在于输出屏幕截图。
M
Max Macfarlane

如果您希望容器的一侧圆角,您可以使用 BorderRadius.only 并指定要圆角的角,如下所示:

Container(
          width: 150.0,
          padding: const EdgeInsets.all(20.0),
          decoration: BoxDecoration(
              borderRadius: BorderRadius.only(
                  topRight: Radius.circular(40.0),
                  bottomRight: Radius.circular(40.0)),
              color: Colors.white),
          child: Text("hello"),
        ),

A
Ashraful

另一种方法是使用 ClipRRect 小部件。只需用 ClipRRect 包裹你的小部件并给出一个半径。您可以指定要圆的角。

ClipRRect(
      borderRadius: BorderRadius.only(topRight: Radius.circular(10)),
      child: Container(
        height: 40,
        width: 40,
        color: Colors.amber,
        child: Text('Hello World!'),
      ),
    );

g
gsm

也可以做如下,

 borderRadius: new BorderRadius.only(
     topLeft: const Radius.circular(30.0),
     bottomLeft: const Radius.circular(30.0),
 ),

N
Nikhil S Marathe

您也可以使用“形状功能”来做到这一点。

  shape: RoundedRectangleBorder(
    borderRadius: BorderRadius.only(
      topRight: Radius.circular(15.0),
      topLeft: Radius.circular(15.0),
    ),

https://i.stack.imgur.com/YQFR5.png


A
Abubakar

您还可以设置每边的半径。

margin: EdgeInsets.fromLTRB(10.0, 10.0, 10.0, 10.0),

fromLTRB= 从左、上、右、下


关注公众号,不定期副业成功案例分享
关注公众号

不定期副业成功案例分享

领先一步获取最新的外包任务吗?

立即订阅