Search code examples
flutterdartflutter-cupertino

How to set width of CupertinoButton in Flutter?


Am I missing something obvious here? Setting minSize on CupertinoButton button sets width and height (see image).

How do I set only the width?

Thanks in advance.

CupertinoButton's minSize


Solution

  • Wrap it in a SizedBox and set width and height.

    Example

    SizedBox(
       width: 500,
       height: 200
       child: CupertinoButton(
           onPressed: (){},
           child: Text("Click Me", style: TextStyle(color: Colors.white)),
           color: Colors.green
       )
    )
    

    NOTE: It is best practice to use SizedBox as it is more efficient since you only need to change the width and height.

    Check this. Flutter: SizedBox Vs Container, why use one instead of the other?