Bandal Kali
Bandal Kali

Reputation: 41

How to set the width and height of a Outlinebutton in Flutter?

I am new in flutter, how to set width and height OutlineButton in Flutter, i have to try input width and height inside OutlineButton but got some errors. this is my code :

OutlinedButton(
  //width: AppSize.DIMEN_230,
  style: OutlinedButton.styleFrom(
    side: BorderSide(
      width: 2.0, color: Colors.black12,
    ),
    shape: RoundedRectangleBorder(
      borderRadius: BorderRadius.circular(10),
  ),),
  onPressed: () {
    showDatePicker(
        context: context,
        initialDate: DateTime.now(),
        firstDate: DateTime(1880),
        lastDate: DateTime(2050),
    );
  }, child: Text("YYYY/MM/DD HH:MM:SS",
      style: textStyleW400S16.copyWith(
        fontStyle: FontStyle.italic,
        color: Colors.black54,
      ),
),
),

Is it correct? Is there another way to do it?

Upvotes: 0

Views: 768

Answers (2)

Ravindra S. Patil
Ravindra S. Patil

Reputation: 14865

Try below code, and refer styleFrom for button style and Size-class for set the width and height of the button and as per your comment I have set your text left-side

   OutlinedButton(
           style: OutlinedButton.styleFrom(
              side: const BorderSide(
                width: 2.0,
                color: Colors.black12,
              ),
              shape: RoundedRectangleBorder(
                borderRadius: BorderRadius.circular(10),
              ),
              fixedSize: const Size(300, 50),//change this width & height your requirnment
            ),
          onPressed: () {
            showDatePicker(
              context: context,
              initialDate: DateTime.now(),
              firstDate: DateTime(1880),
              lastDate: DateTime(2050),
            );
          },
          child: const Align(
            alignment: Alignment.centerLeft,
            child: Text(
              "YYYY/MM/DD HH:MM:SS",
            ),
          ),
        ),

Result-> image

Upvotes: 1

iDecode
iDecode

Reputation: 28996

Wrap your button in SizedBox, and give it width and height.

SizedBox(
  width: 100,
  height: 100,
  child: OutlinedButton(...),
)

Upvotes: 2

Related Questions