Home > Mobile >  Flutter - Setting width of container does not change anything
Flutter - Setting width of container does not change anything

Time:02-23

I am trying to change the with of my container, I need it in the listView course I need it to be scrollable. What am I doing wrong? Here is the code:

  Widget build(BuildContext context) {

return Scaffold(

    body: Container(
        height: height,
        width: width,
        color: Color.fromRGBO(242, 228, 214, 1),
        child: Expanded(
            child: ListView(children: [
          SizedBox(
            height: 20,
          ),
          Container(
            height: 100,
            width: 100,
            decoration: BoxDecoration(
                borderRadius: BorderRadius.circular(20),
                boxShadow: [
                  BoxShadow(
                    color: Colors.grey.withOpacity(0.5),
                    spreadRadius: 2,
                    blurRadius: 10,
                    offset: Offset(0, 3), // changes position of shadow
                  ),
                ],
                color: Color.fromRGBO(247, 241, 236, 1)),
           
              ],
            ),
          ),
        ]))));}}

weirdly without the ListView the Containers can be edited.

CodePudding user response:

We can use ListView's padding to handle this case.

child: ListView(
  padding: EdgeInsets.symmetric(vertical: width * .1),// or use EdgeInsets.only based on your need
  children: [
  • Related