Closed khoadng closed 3 years ago
@khoadng you should attach the AutoScrollController to CustomScrollView Controller. You forgot it. Like this:
CustomScrollView(
controller: **_autoScrollController**, //Attach the controller
...
_wrapScrollTag
...
_wrapScrollTag
...
);
@ariefwijaya Thanks for the suggestion!
I tried to attach the the controller like you said.
body: CustomScrollView(
controller: controller,
slivers: [
SliverToBoxAdapter(
child: ListView(
shrinkWrap: true,
scrollDirection: scrollDirection,
controller: controller,
children: randomList.map<Widget>((data) {
return Padding(
padding: EdgeInsets.all(8),
child: _getRow(data[0], math.max(data[1].toDouble(), 50.0)),
);
}).toList(),
),
)
],
),
but got the exception ScrollController attached to multiple scroll views.
So I removed the controller inside ListView.
body: CustomScrollView(
controller: controller,
slivers: [
SliverToBoxAdapter(
child: ListView(
shrinkWrap: true,
scrollDirection: scrollDirection,
children: randomList.map<Widget>((data) {
return Padding(
padding: EdgeInsets.all(8),
child: _getRow(data[0], math.max(data[1].toDouble(), 50.0)),
);
}).toList(),
),
)
],
),
It works! But unfortunately, you can't scroll with your finger anymore.
It works! But unfortunately, you can't scroll with your finger anymore.
@khoadng You can't scroll it because you used ListView vertical Inside CustomScrollView. Don't do it if you want that behaviour. Instead, use SliverList and SliverChildBuilderDelegate for the best performance.
body: CustomScrollView(
controller: controller,
slivers: [
/*SliverToBoxAdapter(
child: ListView(
shrinkWrap: true,
scrollDirection: scrollDirection,
children: randomList.map<Widget>((data) {
return Padding(
padding: EdgeInsets.all(8),
child: _getRow(data[0], math.max(data[1].toDouble(), 50.0)),
);
}).toList(),
),
)*/
SliverList(
delegate: SliverChildBuilderDelegate(
(context, i){
final data = randomList[i];
return Padding(
padding: EdgeInsets.all(8),
child: _getRow(data[0], math.max(data[1].toDouble(), 50.0)),
);
},
childCount: randomList.length,
),
)
],
),
@ariefwijaya Thanks for the suggestion!
I tried to attach the the controller like you said.
body: CustomScrollView( controller: controller, slivers: [ SliverToBoxAdapter( child: ListView( shrinkWrap: true, scrollDirection: scrollDirection, controller: controller, children: randomList.map<Widget>((data) { return Padding( padding: EdgeInsets.all(8), child: _getRow(data[0], math.max(data[1].toDouble(), 50.0)), ); }).toList(), ), ) ], ),
but got the exception
ScrollController attached to multiple scroll views.
So I removed the controller inside ListView.body: CustomScrollView( controller: controller, slivers: [ SliverToBoxAdapter( child: ListView( shrinkWrap: true, scrollDirection: scrollDirection, children: randomList.map<Widget>((data) { return Padding( padding: EdgeInsets.all(8), child: _getRow(data[0], math.max(data[1].toDouble(), 50.0)), ); }).toList(), ), ) ], ),
It works! But unfortunately, you can't scroll with your finger anymore.
To Keep scroll working use this two lines inside ListView: physics: const NeverScrollableScrollPhysics(), shrinkWrap: true,
@indianictarun @ariefwijaya thanks for help.
@khoadng, does above suggestions work?
@jerrywell Sorry I haven't tried these solutions yet since I’m swamped with my current work! I will try them this weekend and get back to you later.
Works great! I am closing this now.
I modified the example a bit to reproduce the issue.