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

OutlinedButton exception when trying to set max size

I’m trying to create something like the below image:

enter image description here

I used two OutlinedButton in a row:

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

Row(
        mainAxisAlignment: MainAxisAlignment.start,
        children: <Widget>[
          OutlinedButton(
              child: const Icon(
                Icons.arrow_back,
                color: colorBackButton,
              ),
              style: ButtonStyle(
                  fixedSize: MaterialStateProperty.resolveWith(
                      (states) => Size(65.0, 65.0)))),
          Padding(padding: EdgeInsets.only(left: 14.0)),

          OutlinedButton(
                child: Text(
                  'Next',
                  style: GoogleFonts.inter(
                      textStyle: const TextStyle(
                          fontSize: 20,
                          fontWeight: FontWeight.bold,
                          color: Colors.white)),
                ),
                style: ButtonStyle(
                  backgroundColor:
                      MaterialStateProperty.resolveWith((states) {
                    return colorPrimaryButton;
                  }),
                }),

        ])

This has led me to this result:

enter image description here

I tried to wrap the Next button with Sizedbox.expand and also add a minimumSize to the button style:

minimumSize: MaterialStateProperty.resolveWith((states) => const Size.fromHeight(55.0))

Both results with a BoxConstraints forces an infinite width. These invalid constraints were provided to RenderPhysicalShape's layout() function by t

Digging into the exception, it’s written:

The offending constraints were: BoxConstraints(w=Infinity, 55.0<=h<=Infinity)

How can I make the Next button fill the entire row’s space (discluding the padding of course)?

>Solution :

You can wrap with Expanded widget to get maximum available space.

Row(
    mainAxisAlignment: MainAxisAlignment.start,
    children: <Widget>[
      OutlinedButton(
        onPressed: () {},
        child: const Icon(
          Icons.arrow_back,
          color: Colors.amber,
        ),
        style: ButtonStyle(
          fixedSize: MaterialStateProperty.resolveWith(
            (states) => const Size(65.0, 65.0),
          ),
        ),
      ),
      Expanded(
        child: Padding(
          padding: const EdgeInsets.only(left: 14.0),
          child: OutlinedButton(
            onPressed: () {},
            child: const Text('Next',
                style: TextStyle(
                    fontSize: 20,
                    fontWeight: FontWeight.bold,
                    color: Colors.white)),
            style: ButtonStyle(
              backgroundColor:
                  MaterialStateProperty.all(Colors.deepPurple),
              fixedSize: MaterialStateProperty.resolveWith(
                (states) => const Size(65.0, 65.0),
              ),
            ),
          ),
        ),
      ),
    ],
  );

enter image description here

You can play with padding. Also, you can use LayoutBuilder.

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