Home > database >  Make horizontal CustomScrollView also vertically scrollable flutter
Make horizontal CustomScrollView also vertically scrollable flutter

Time:10-07

I have a CustomScrollView demonstration:

CustomScrollView(
        scrollDirection: Axis.horizontal,
        slivers: <Widget>[
          SliverToBoxAdapter(child: Container(
          height: 800, width: 200, color: Colors.red)),
          SliverList(
            delegate: SliverChildBuilderDelegate(
              childCount: 30,
              (BuildContext context, int index) {
                return Container(
                  padding: const EdgeInsets.all(16),
                  alignment: Alignment.center,
                  color: Colors.blue,
                  height: 800,
                  child: Text('Item: $index'),
                );
              },
            ),
          ),
          SliverToBoxAdapter(child: Container(
          height: 800, width: 200, color: Colors.red)),
        ],
      )

I am able to scroll horizontally fine. My problem is that, since items can be big height wise, I want to add the ability to scroll the whole CustomScrollView vertically also.

I want to keep the CustomScrollView due to some complications which are out of context for this problem.

How may I achieve the ability to scroll the whole CustomScrollView vertically while also keeping the ability to scroll it horizontally?

CodePudding user response:

Wrap the CustomScrollView with SingleChildScrollView and then wrap the SingleChildScrollView with a Container/SizedBox and give it a proper height

CodePudding user response:

Wrap you customscrollview within singlechildscrollview and set scroll direction to vertical in singlechildscrollview and set scroll direction horizontal in customchildscrollview and then you can scroll in any direction.

  • Related