Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Boxshadow appears behind other widgets

I have a Container with a BoxShadow decoration at the top of a page, and below the Container is a ListView with a number of Cards in it. I want the top Container to have a drop shadow that appears in front of the items in the ListView, but this is what I get:

enter image description here

The drop shadow seems to appear behind the Cards instead of in front of it. This is the code:

Widget _buildBody(BuildContext context, ChecklistModel model){
    return Container(
        child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: <Widget>[
                Container(
                    decoration: BoxDecoration(
                        color: Colors.red.shade200,
                        boxShadow: [BoxShadow(
                            color: Colors.red.shade200,
                            offset: Offset(0, 10),
                            blurRadius: 10,
                            spreadRadius: 10
                        )]
                    ),
                    child: ListTile(
                        title: Text(''),
                    )
                ),
                Expanded(child: Padding(
                    padding: const EdgeInsets.all(10),
                    child: _buildCheckpointListView(context, model))
                )
            ],
        )
    );
}

I also tried replacing the Container with a Card, but that didn't work either.

like image 953
Magnus Avatar asked Mar 22 '19 09:03

Magnus


People also ask

What is offset in BoxShadow Flutter?

color: The color property takes Color class as the object to decide the color of the shadow. offset: Offset class is the object given to this property which controls the extent to which the shadow will be visible.

How to give Box shadow to container in Flutter?

Step 1: Add the Container widget. Step 2: Add the decoration parameter (inside Container) and assign the BoxDecoration class. Step 3: Add the boxShadow parameter (inside BoxDecoration) and assign the BoxShadow class. Step 4: Add the blurRadius parameter (inside BoxShadow) and set the value to 25.

How do I show widgets from another widget in flutter?

In Flutter, the overlay lets you print visual elements on top of other widgets by inserting them into the overlay's stack. You insert a widget into the overlay using an OverlayEntry and you use Positioned and AnimatedPositioned to choose where the entry is positioned within the overlay.


1 Answers

Give a bottom margin to the container to introduce some empty space between container and bottom siblings. Like this :

        Container(
        margin: EdgeInsets.only(bottom: 20),
          decoration: BoxDecoration(
              color: Colors.red.shade200,
              boxShadow: [BoxShadow(
                  color: Colors.red.shade200,
                  offset: Offset(0, 10),
                  blurRadius: 10,
                  spreadRadius: 10
              )]
          ),
          child: ListTile(
            title: Text(''),
          )
      ),
like image 158
Ryosuke Avatar answered Nov 05 '22 22:11

Ryosuke