Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter - Container BoxShadow disappears on scroll in a ListView

Tags:

This is what my Container looks like:

new Container(         width: 500.0,         height: 250.0,         padding: new EdgeInsets.fromLTRB(20.0, 40.0, 20.0, 40.0),         decoration: new BoxDecoration(           color: const Color(0xFF66BB6A),           boxShadow: [new BoxShadow(             color: Colors.black,             blurRadius: 20.0,           ),]         ),         child: new Column(           mainAxisAlignment: MainAxisAlignment.center,           children: [             new Container(               padding: new EdgeInsets.fromLTRB(0.0, 0.0, 0.0, 10.0),               child: new Text("Testtext", style: new TextStyle(fontSize: 30.0, fontFamily: "Barrio", color: new Color.fromARGB(255, 230, 230, 230))),             ),           ]         ),       ), 

It is inside a ListView with some other Containers. As soon as I start scrolling through the ListView, the shadow just disappears. When loading the view tho, it appears correctly.

Any thoughts on this problem?

Thanks

like image 999
OhMad Avatar asked May 06 '17 13:05

OhMad


People also ask

How to apply a box shadow on the container widget of flutter?

While making beautiful UI, the box-shadow property is very important during designing. See the example below and learn how to apply a box-shadow on the Container widget of Flutter. To apply box shadow, use the following code: BoxShadow(color: Colors.grey.withOpacity(0.5), spreadRadius: 5, blurRadius: 7, offset: Offset(0, 2),)

Why we use listview instead of column in flutter?

This way there is no chance that you will get any overflow error like you were getting while using Column. Plus point of ListView.builder is that your posts will be created lazily and that is efficient way of creating ListView in Flutter. No matter how many posts you have your UI will not lag.

Why is there a shadow in my listview?

Most likely the other items in your ListView are covering up your manually drawn shadow because it's being drawn outside the bounds of your Container. I would recommend that you use a Card instead of a container.

How to assign scrollcontroller to floatingactionbutton in listview?

ScrollController listScrollController = ScrollController (); Now assign this ScrollController to the controller field of ListView. Now come to the onPressed () field of FloatingActionButton. We have first checked whether we can communicate with the members of ScrollController using If not checked, we will get a runtime error.


Video Answer


2 Answers

This other answer is for those who need to continue with Container:

Container(   decoration: BoxDecoration(     shape: BoxShape.circle, // BoxShape.circle or BoxShape.retangle     //color: const Color(0xFF66BB6A),     boxShadow: [BoxShadow(       color: Colors.grey,       blurRadius: 5.0,     ),]   ),   child: ... ), 
like image 152
Edeson Bizerril Avatar answered Sep 21 '22 13:09

Edeson Bizerril


I was trying to reproduce the issue, and I noticed that you didn't put any margin on your Container. Most likely the other items in your ListView are covering up your manually drawn shadow because it's being drawn outside the bounds of your Container.

I would recommend that you use a Card instead of a container. You can get a natural-looking material shadow using the elevation constructor argument. Cards come with some built-in margin, and you can add more by enclosing it in a Container if you want. This will give you enough space for the shadow to be visible. You can control the color of the Card with the color constructor argument.

The corners of a Card are slightly rounded. If you don't want rounded corners, you're going to be going off spec from Material design, but you could try enclosing a Material with a type of MaterialType.canvas inside a Container.

like image 31
Collin Jackson Avatar answered Sep 19 '22 13:09

Collin Jackson