Search code examples
androidflutterpadding

ListWheelScrollView using flutter


Am trying to add a ListWheelScrollView to my screen but am facing a problem where it's adding a top padding

I expected the ListWheelScrollView to be paleced on top but it's as you can see in the picture below positioned at the center of the screenenter image description here

return Scaffold(
        body: Container(
      child: RotatedBox(
          quarterTurns: -1,
          child: MediaQuery.removePadding(
              context: context,
              removeTop: true,
              child: ListWheelScrollView(
                magnification: 2.0,
                onSelectedItemChanged: (x) {
                  setState(() {
                    selected = x;
                  });
                  print(selected);
                },
                controller: _scrollController,
                children: List.generate(
                    itemCount,
                    (x) => RotatedBox(
                        quarterTurns: 1,
                        child: AnimatedContainer(
                            duration: Duration(milliseconds: 400),
                            width: x == selected ? 70 : 60,
                            height: x == selected ? 80 : 70,
                            alignment: Alignment.center,
                            decoration: BoxDecoration(
                                color: x == selected
                                    ? Color.fromRGBO(249, 220, 222, 1)
                                    : Colors.transparent,
                                shape: BoxShape.rectangle,
                                borderRadius: BorderRadius.circular(15)),
                            child: Text('week \n \n   $x')))),
                itemExtent: itemWidth,
              ))),
    ));

Solution

  • Set up Height for Container like 100,200,....

    If not, Widget will spread entire screen

    Don't forget remove unnessary code from your code: MediaQuery.removePadding