How to put text under Boxdecoration Flutter

Asked

Viewed 576 times

-1

Hello!

I’d like to do the following :

inserir a descrição da imagem aqui

A list that shows people online, with their name down. Only I managed to do the following:

inserir a descrição da imagem aqui

I would like to put a name underneath the image of the person. I couldn’t find out how to do it, and I tried to put a child: Text() into the container, but it didn’t work.

My code is like this:

Widget _listOnline() {
    return ListView(
      scrollDirection: Axis.horizontal,
      children: [
        Container(
          padding: EdgeInsets.only(left: 35),
          width: 80,
          height: 80,
          decoration: BoxDecoration(
            shape: BoxShape.circle,
            image: DecorationImage(
              image: AssetImage("images/Rubio_Circle.png"),
            ),
          ),
        ),
      ],
    );
  }

1 answer

2


All you need to do is use one Column with the widgets Container and Text.

I advise you to create a separate widget for the items, where you receive as parameter the text and the image you want... So you replace all the code of "Item 1" by the widget created, thus saving lines and leaving more organized.

   Widget _listOnline() {
        return ListView(
          scrollDirection: Axis.horizontal,
          children: [
            Column( /* Item 1 */
              mainAxisAlignment: MainAxisAlignment.start,
              crossAxisAlignment: CrossAxisAlignment.center,
              children: [
                Container(
                  padding: EdgeInsets.only(left: 35),
                  width: 80,
                  height: 80,
                  decoration: BoxDecoration(
                    shape: BoxShape.circle,
                    image: DecorationImage(
                      image: AssetImage("images/Rubio_Circle.png"),
                    ),
                  ),
                ),
                Text("Nome aqui")
              ],
            ),
            Column( /* Item 2 */
              mainAxisAlignment: MainAxisAlignment.start,
              crossAxisAlignment: CrossAxisAlignment.center,
              children: [
                Container(
                  padding: EdgeInsets.only(left: 35),
                  width: 80,
                  height: 80,
                  decoration: BoxDecoration(
                    shape: BoxShape.circle,
                    image: DecorationImage(
                      image: AssetImage("images/Rubio_Circle.png"),
                    ),
                  ),
                ),
                Text("Nome aqui")
              ],
            ),
          ],
        );
      }
  • 1

    Thank you so much for the tips, I did as you said, I created another widget and passed as parameters, easier to call too, thanks

  • I posted one more question that maybe you can help me, if you can clear

Browser other questions tagged

You are not signed in. Login or sign up in order to post.