1

我有圆形头像。我想circle's avataravatar. 但我不能这样做。当我运行下面的代码时,text出现在avatar.

我的代码

child: Container(
              height: 60.0,
              width: 60.0,
              margin: EdgeInsets.all(6.0),
              decoration: BoxDecoration(
                  borderRadius: BorderRadius.circular(100.0),
                  boxShadow: [
                    new BoxShadow(
                        color: Color.fromARGB(100, 20, 0, 0),
                        blurRadius: 5.0,
                        offset: Offset(5.0, 5.0))
                  ],
                  border: Border.all(
                      width: 2.0,
                      style: BorderStyle.solid,
                      color: Colors.purple),
                  image: DecorationImage(
                      fit: BoxFit.cover,
                      image: NetworkImage(userData[x]["image"]))),
                      child: new Text(userData[x]["name"], style: TextStyle(fontSize: 20.0),),
                      )
                      ));

4

3 回答 3

3

如果您尝试像这样实现:

在此处输入图像描述

然后你可以使用ColumnStack小部件。我将StackAlign小部件一起使用。

代码:


Container(
       height: 80.0,
       width: 80.0,
       child: Stack(
        children: <Widget>[
           Container(
             height: 60.0,
             width: 60.0,
             margin: EdgeInsets.all(6.0),
             decoration: BoxDecoration(
               //  shape: BoxShape.circle,
                 borderRadius: BorderRadius.circular(100.0),
                 boxShadow: [
                   new BoxShadow(
                       color: Color.fromARGB(100, 20, 0, 0),
                       blurRadius: 5.0,
                       offset: Offset(5.0, 5.0))
                 ],
                 border: Border.all(
                     width: 2.0,
                     style: BorderStyle.solid,
                     color: Colors.purple),
                 image: DecorationImage(
                     fit: BoxFit.cover,
                     image: NetworkImage("https://image.shutterstock.com/image-photo/cute-baby-girl-sitting-on-260nw-689375770.jpg"))),
                   // child:
           ),
           Align(
             alignment: Alignment.bottomCenter,
             child:  new Text("name", style: TextStyle(fontSize: 20.0),),
           )
         ],
      ),
    )

于 2020-03-13T12:46:58.017 回答
1

您可以尝试以下方法:

Container(
      child: Column(
        children: <Widget>[
          Container(
            height: 60.0,
            width: 60.0,
            alignment: Alignment.bottomCenter,
            margin: EdgeInsets.all(6.0),
            decoration: BoxDecoration(
                borderRadius: BorderRadius.circular(100.0),
                boxShadow: [
                  new BoxShadow(
                      color: Color.fromARGB(100, 20, 0, 0),
                      blurRadius: 5.0,
                      offset: Offset(5.0, 5.0))
                ],
                border: Border.all(
                    width: 2.0,
                    style: BorderStyle.solid,
                    color: Colors.purple),
                image: DecorationImage(
                    fit: BoxFit.cover,
                    image: NetworkImage(
                        "https://source.unsplash.com/random"))),
          ),
          Text(
            "text....",
            style: TextStyle(fontSize: 16.0),
          )
        ], 
      ),
    )
于 2020-03-13T12:19:13.213 回答
0

您可以使用堆栈小部件,如下所示:-

Container(
          height: 60,
          child: Stack(
            children: <Widget>[
            Container(
            height: 60.0,
            width: 60.0,
            margin: EdgeInsets.all(6.0),
            decoration: BoxDecoration(
                borderRadius: BorderRadius.circular(100.0),
                boxShadow: [
                  new BoxShadow(
                      color: Color.fromARGB(100, 20, 0, 0),
                      blurRadius: 5.0,
                      offset: Offset(5.0, 5.0))
                ],
                border: Border.all(
                    width: 2.0,
                    style: BorderStyle.solid,
                    color: Colors.purple),
                image: DecorationImage(
                    fit: BoxFit.cover,
                    image: NetworkImage(userData[x]["image"]))),
          ),
              Positioned(
                bottom: 5.0,
                right:5.0
                child: Text(userData[x]["name"], style: TextStyle(fontSize: 20.0),),
              )
            ],
          ),
        )
于 2020-03-13T11:51:21.193 回答