简体   繁体   English

Flutter 带边框圆形头像

[英]Flutter CIrcle Avatar With Border

I am trying to create circle avatar with border in Flutter using CircleAvatar widget like:我正在尝试使用CircleAvatar小部件在 Flutter 中创建带边框的圆形头像,例如:

CircleAvatar(
    radius: 30,
    backgroundImage: NetworkImage(url),
  ),

How can I add border to the result of this code?如何为这段代码的结果添加边框?

Wrap CircleAvatar widget within another CircleAvatar widget and then set different radius and backgroundColor to achieve the required border.CircleAvatar小部件包裹在另一个CircleAvatar小部件中,然后设置不同的半径和背景颜色以实现所需的边框。

Here is the code snippet这是代码片段

CircleAvatar(
    radius: 30,
    backgroundColor: Colors.teal,
    child: CircleAvatar(
      backgroundImage: AssetImage(url),
      radius: 28,
    ),
  ),

Code Snippet Link 代码片段链接

only use colors仅使用 colors

CircleAvatar(
        backgroundColor: Colors.red,
        radius: 70.0,
        child: CircleAvatar(
          backgroundColor: Colors.orange,
          radius: 60,
        ),
      ),

when use from local storage从本地存储使用时

CircleAvatar(
        backgroundColor: Colors.white,
        radius: 70,
        child: CircleAvatar(
          backgroundImage: AssetImage("image/bg.jpg"),
          radius: 60,
        ),
      ),

if use image from network如果使用来自网络的图像

      CircleAvatar(
        backgroundColor: Colors.white,
        radius: 70,
        child: CircleAvatar(
          backgroundImage: NetworkImage(url),
          radius: 60,
        ),
      ),

Like indicated in comments a quite flexible way is to wrap it inside a Container:就像评论中指出的那样,一种非常灵活的方法是将其包装在容器中:

  @override
  Widget build(BuildContext context) {
    return Container(
      decoration: BoxDecoration(
        shape: BoxShape.circle,
        border: Border.all(color: Colors.white),
      ),
      child: CircleAvatar(
        // your avatar properties here
      ),
    );
  }

So you can quite freely define how your border should look like eg use "strokeAlign"-Property of the Border.all-Method to define whether the border should use the space inside the CircleAvatar or outside of it.因此,您可以完全自由地定义边框的外观,例如使用 Border.all 方法的“strokeAlign”属性来定义边框是应使用 CircleAvatar 内部空间还是外部空间。

Check this link.检查链接。 you will get the code snippet if not here is the code bellow.如果不是下面的代码,您将获得代码片段。

the code is;代码是;

CircleAvatar(
              radius: 55,
              backgroundColor: Colors.teal,
              child: CircleAvatar(
                radius: 50,
                backgroundImage: NetworkImage('url'),
              ),
            )

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM