I am facing a problem of 2 listViews scrolled at the same time :
DefaultTabController(
length: 2,
child: NestedScrollView
(
headerSliverBuilder: (context, innerBoxIsScrolled)
{
return
[
SliverAppBar(
title: Text('HOME', style: Theme.of(context).textTheme.headline5,),
floating: true,
pinned: false,
snap: true,
titleSpacing: 0.1,
bottom: TabBar(
isScrollable: true,
indicatorSize: TabBarIndicatorSize.label,
labelPadding: EdgeInsets.symmetric(horizontal: 60),
controller: tabController,
tabs:
[
Tab(child: Text('Tab 1', style: Theme.of(context).textTheme.headline6,)),
Tab(child: Text('Tab 2', style: Theme.of(context).textTheme.headline6)),
],
),
),
];
}, //header sliver builder
body: TabBarView(
controller: tabController,
children:
[
ListViews1, //ListView.builder
ListViews2 //ListView.builder
],
),
)
),
The tabbar controller listens to change when swiped or clicked on the tab. Indexed are being returned correctly. 0 for 1st tab and 1 for 2nd tab
tabController = TabController(length: 2, vsync: this);
tabController.addListener(_handleTabSelection);
void _handleTabSelection() {
if(!tabController.indexIsChanging)
{
log('CALLED : ${tabController.index}');
}
}
Both classes are kept alive so that the scroll position shouldn't get lost:
class _ListView1State extends State<ListView1> with AutomaticKeepAliveClientMixin<ListView1>{
@override
bool get wantKeepAlive => true;
class _ListView2State extends State<ListView2> with AutomaticKeepAliveClientMixin<ListView2>{
@override
bool get wantKeepAlive => true;
PROBLEM : When i scroll the first list, the 2nd list also gets scrolled automatically and vice versa. What is the problem here ?