vertical_scrollable_tabview 0.0.4 vertical_scrollable_tabview: ^0.0.4 copied to clipboard
A Flutter widget which syncronize a ScrollView and a custom tab view.
import 'package:flutter/material.dart';
import 'package:vertical_scrollable_tabview/vertical_scrollable_tabview.dart';
import 'category_section.dart';
import 'example_data.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Vertical Scrollable TabView Demo',
theme: ThemeData(
primarySwatch: Colors.purple,
),
home: MyHomePage(title: 'Vertical Scrollable TabView Plugin'));
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key? key, required this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage>
with SingleTickerProviderStateMixin {
final List<Category> data = ExampleData.data;
// TabController More Information => https://api.flutter.dev/flutter/material/TabController-class.html
late TabController tabController;
@override
void initState() {
tabController = TabController(length: data.length, vsync: this);
super.initState();
}
@override
void dispose() {
tabController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
appBar: AppBar(
title: Text(widget.title),
bottom: TabBar(
isScrollable: true,
controller: tabController,
indicatorPadding: EdgeInsets.symmetric(horizontal: 16.0),
indicatorColor: Colors.cyan,
labelColor: Colors.cyan,
unselectedLabelColor: Colors.white,
indicatorWeight: 3.0,
tabs: data.map((e) {
return Tab(text: e.title);
}).toList(),
onTap: (index) {
VerticalScrollableTabBarStatus.setIndex(index);
},
),
),
body: VerticalScrollableTabView(
tabController: tabController,
listItemData: data,
verticalScrollPosition: VerticalScrollPosition.middle,
//Change this to your preferred scroll direction
scrollDirection: Axis.vertical,
eachItemChild: (object, index) =>
CategorySection(category: object as Category)),
);
}
}