Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Stick two elements side by side in a Row

In order to show my username and the ability to edit it, I would like to place a text with the username and an IconButton for editing side by side (or with minimal space between them). However, when I put these two elements in a Row, Flutter keeps a space between them that I can’t remove.

Here is my code:

Row(
  mainAxisSize: MainAxisSize.min,
  children: [
    Text(
      "%${userProvider.userAccount?.pseudo}",
      style: Theme.of(context).textTheme.bodyMedium!.copyWith(
        color: themeProvider.isDarkMode
            ? Colors.white
            : Colors.grey,
      ),
    ),
    IconButton(
      padding: EdgeInsets.zero,  
      constraints: BoxConstraints(),  
      onPressed: () {},
      icon: Icon(Icons.edit, size: 15),
    ),
  ],
)

ResultsImage

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Is there a solution to remove or control this space in my code?

>Solution :

You can resolve the issue by changing the IconButton to an InkWell widget. Here’s how you can do it:

InkWell(
  onTap: () {
    // Add your onTap functionality here
  },
  child: Icon(Icons.edit, size: 15),
)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading