How to alight last child of row to alight completely right?

I have a ROW with 3 children.

Container(
              alignment: Alignment.center,
              margin: const EdgeInsets.all(20.0),
              child: Row(
                children: [
                  Text(
                      'hello'
                    ),
                  Padding(
                    padding: const EdgeInsets.only(left: 15.0),
                    child: SizedBox(
                        child: Text(
                      'hello'
                    )),
                  ),
                  PopupMenuButton(
                    itemBuilder: (BuildContext context) {
                      return [
                        PopupMenuItem(
                          child: Text('asdasd'),
                        )
                      ];
                    },
                  )
                ],
              ),
            )

Now I want last PopupMenuButton to completely right (Basically at the end of the containter widget.)

How can i do that?

>Solution :

Add a spacer()

Container(
              alignment: Alignment.center,
              margin: const EdgeInsets.all(20.0),
              child: Row(
                children: [
                  Text(
                      'hello'
                    ),
                  Padding(
                    padding: const EdgeInsets.only(left: 15.0),
                    child: SizedBox(
                        child: Text(
                      'hello'
                    )),
                  ),
                 Spacer(), //here
                  PopupMenuButton(
                    itemBuilder: (BuildContext context) {
                      return [
                        PopupMenuItem(
                          child: Text('asdasd'),
                        )
                      ];
                    },
                  )
                ],
              ),
            )

If it throws unbound error then add a width to the container

width : MediaQuery.of(context).size.width,

More about spacer

Leave a Reply