How can I switch tabs on a vertical scroll as shown above. What would be the best way to do this? And upon clicking on certain tab, control should be transfer to selected tab content. I tried to find solution on google but in vain.
Currently my code looks something like this but I know thats not it.
class SingleRestView extends StatefulWidget {
Restaurant singleRestaurant;
SingleRestView({@required this.singleRestaurant});
@override
_SingleRestViewState createState() => _SingleRestViewState();
}
class _SingleRestViewState extends State<SingleRestView>
with SingleTickerProviderStateMixin {
var _tabController;
@override
void initState() {
super.initState();
_tabController = TabController(length: 3, vsync: this);
}
@override
Widget build(BuildContext context) {
var tabBar = TabBar(
controller: _tabController,
//This property will allow your tabs to be horizontally scrollable
isScrollable: true,
indicatorColor: Colors.black,
labelColor: Colors.black,
tabs: [
Text("Tab 1"),
Text("Tab 2"),
Text("Tab 2"),
],
);
return Scaffold(
body: NestedScrollView(
headerSliverBuilder: (context, isScrolled) => [
SliverAppBar(
expandedHeight: 300,
pinned: true,
flexibleSpace: FlexibleSpaceBar(
title: Text('Title'),
//Without this padding the title appears behind the tabs.
//This is the whole reason why the tabBar is in a local variable, to
//be able to use its height here.
titlePadding: EdgeInsetsDirectional.only(
start: 72, bottom: tabBar.preferredSize.height + 16),
// background:
),
// I did this this way to have a white bottom bar like in your photo,
// however, you could just pass the tabBar. The background image would
//be behind it.
bottom: PreferredSize(
child: Container(
//This will keep your tabs centered if you have not enough to fill
//the display's width
alignment: Alignment.center,
width: double.infinity,
color: Colors.white,
child: tabBar,
),
preferredSize: Size(double.infinity, tabBar.preferredSize.height),
),
),
],
body: TabBarView(
controller: _tabController,
children: <Widget>[
Container(height: 50,width: 100,color: Colors.red,),
Container(height: 50,width: 100,color: Colors.blue,),
Container(height: 50,width: 100,color: Colors.green,),
],
),
),
);
}
}