Search code examples
flutterdartflutter-layoutflutter-container

Why do I have a shape behind my image in a container?


I tried to make a card with round corners, but when I did so, the card below the image was bigger than the image. Below is my code and a screenshot of a part of my app to show you my problem. I hope you can see on the screenshot that next to the image, in the corners is a shape.

Card(
                child: InkWell(
                  splashColor: Colors.blue.withAlpha(30),
                  onTap: () {
                    Navigator.of(context).push(MaterialPageRoute(
                      builder: (context) => BodyConstruction(),
                    ));
                  },
                  child: ClipRRect(
                    borderRadius: BorderRadius.all(Radius.circular(30)),
                    child: Image.asset('images/Bild1.jpg'),
                  )
                ),
              ),

the screenshot of my card


Solution

  • You forgot to add the shape of your Card. Also, you can simplify your borderRadius:

    Card(shape: RoundedRectangleBorder(
                borderRadius: BorderRadius.circular(30)
          ),
          child: InkWell(
                splashColor: Colors.blue.withAlpha(30),
                onTap: () {
                   Navigator.of(context).push(MaterialPageRoute(
                      builder: (context) => BodyConstruction(),
                    ));
                },
                child: ClipRRect(
                  borderRadius: BorderRadius.circular(30),
                  child: Image.asset('images/Bild1.jpg'),
                ),
              ),
            )
    

    Your result will be the following:

    example