Search code examples
flutterdartflutter-layout

Flutter ElevatedButton with Image cover


I want to create a rounded ElevatedButton with an image background cover as the following:

enter image description here

Right now my ElevatedButton show that result:

enter image description here

ElevatedButton(
      onPressed: () {},
      style: ElevatedButton.styleFrom(shape: const StadiumBorder()),
      child: Image.network('url...', fit: BoxFit.cover),
    )

Can someone give me an example of how to add a background image to a rounded ElevatedButton?


Solution

  • Use clipBehavior and padding like this:

    SizedBox(
        height: 100,
        child: ElevatedButton(
            onPressed: () {},
            clipBehavior: Clip.antiAlias,// <--add this
            style: ElevatedButton.styleFrom(
                shape: RoundedRectangleBorder(
                borderRadius: BorderRadius.circular(18.0), // <--add this
                ),
                padding: EdgeInsets.zero, // <--add this
            ),         
            child: Image.network('url...', fit: BoxFit.cover),
        ),
    ),
    

    enter image description here