flutter - 带有底部文本字段的容器

flutter - Container with bottom text field

我有圆形头像。我想在 avatar 的底部添加每个 circle's avatar 名称。但我不能这样做。当我 运行 下面的代码时, 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),),
                      )
                      ));

您可以像这样使用堆栈小部件:-

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

您可以尝试如下操作:

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

如果您尝试这样实施:

然后您可以使用 ColumnStack 小部件。 我使用了 Stack with Align 小部件。

代码:


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