A Flutter library for creating scrollable tab views with headers and items. This library provides a controller to manage the state and behavior of the tabs and scroll view, enabling smooth scrolling and tab selection interactions.
- Scrollable tabs with headers and items.
- Customizable tab headers, group headers, and item builders.
- Smooth scrolling and tab selection synchronization.
dependencies:
scrollable_tab: any
Then, run flutter pub get
to install the package.
import 'package:scrollable_tab/scrollable_tab.dart';
import 'package:scrollable_tab/scrollable_tab.dart';
final tabItems = [
TabHeaderItems(
name: 'Tab 1',
items: ['Item 1.1', 'Item 1.2', 'Item 1.3'],
),
TabHeaderItems(
name: 'Tab 2',
items: ['Item 2.1', 'Item 2.2'],
),
// Add more tabs as needed
];
import 'package:flutter/material.dart';
import 'package:scrollable_tab/scrollable_tab.dart';
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(title: Text('Scrollable Tab View')),
body: ScrollableTabView<String>(
tabItems: tabItems,
tabHeaderBuilder: (tabInfo) => Tab(text: tabInfo.header.name),
groupHeaderBuilder: (header) => Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
header.name,
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
),
),
itemBuilder: (item) => ListTile(title: Text(item)),
),
),
);
}
}
void main() => runApp(MyApp());
If you need to customize the controller or use an existing ScrollController
, you can create the ScrollableTabView
with a custom controller.
final customController = ScrollableTabController<String>(tabItems: tabItems);
ScrollableTabView<String>(
controller: customController,
tabHeaderBuilder: (tabInfo) => Tab(text: tabInfo.header.name),
groupHeaderBuilder: (header) => Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
header.name,
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
),
),
itemBuilder: (item) => ListTile(title: Text(item)),
);
Make sure to call init method of the ScrollableTabController
in order to intialize the ScrollController
and TabController
customController.init(this);
Note: this
is a TickerProvider which comes from TickerProviderStateMixin
class.
Carefully dispose the controller in the dispose method.
customController.dispose();
A class that represents the header items for each tab.
name
: The name of the tab header.extras
: Additional data for the header.items
: A list of items under this header.
A controller for managing the state and behavior of the scrollable tab view.
tabItems
: The list of tab header items.scrollController
: An optional externalScrollController
.
A widget that provides a scrollable tab view.
tabItems
: The list of tab header items.tabHeaderBuilder
: A builder for creating tab headers.groupHeaderBuilder
: A builder for creating group headers.itemBuilder
: A builder for creating items.controller
: An optional customScrollableTabController
._scrollController
: An optional customScrollController
.
import 'package:flutter/material.dart';
import 'package:scrollable_tab/scrollable_tabdart';
final tabItems = [
TabHeaderItems(
name: 'Tab 1',
items: ['Item 1.1', 'Item 1.2', 'Item 1.3'],
),
TabHeaderItems(
name: 'Tab 2',
items: ['Item 2.1', 'Item 2.2'],
),
// Add more tabs as needed
];
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(title: Text('Scrollable Tab View')),
body: ScrollableTabView<String>(
tabItems: tabItems,
tabHeaderBuilder: (tabInfo) => Tab(text: tabInfo.header.name),
groupHeaderBuilder: (header) => Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
header.name,
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
),
),
itemBuilder: (item) => ListTile(title: Text(item)),
),
),
);
}
}
void main() => runApp(MyApp());
This project is licensed under the MIT License - see the LICENSE file for details.