extended_tabs
一个强大的官方扩展库,用于 Tab/TabBar/TabView,支持在当前选项卡滚动超出范围时滚动祖先或子选项卡,并设置滚动方向和缓存范围。
用法
dependencies:
flutter:
sdk: flutter
extended_tabs: any
ColorTabIndicator
显示带有颜色填充的选项卡指示器
TabBar(
indicator: ColorTabIndicator(Colors.blue),
labelColor: Colors.black,
tabs: [
Tab(text: "Tab0"),
Tab(text: "Tab1"),
],
controller: tabController,
)
链接
/// if link is true and current tabbarview over scroll,
/// it will check and scroll ancestor or child tabbarView.
/// default is true
final bool link;
ExtendedTabBarView(
children: <Widget>[
List("Tab000"),
List("Tab001"),
List("Tab002"),
List("Tab003"),
],
controller: tabController2,
link: true,
)
滚动方向
/// The axis along which the tab bar and tab view scrolls.
///
/// Defaults to [Axis.horizontal].
final Axis scrollDirection;
Row(
children: <Widget>[
ExtendedTabBar(
indicator: const ColorTabIndicator(Colors.blue),
labelColor: Colors.black,
scrollDirection: Axis.vertical,
tabs: const <ExtendedTab>[
ExtendedTab(
text: 'Tab0',
scrollDirection: Axis.vertical,
),
ExtendedTab(
text: 'Tab1',
scrollDirection: Axis.vertical,
),
],
controller: tabController,
),
Expanded(
child: ExtendedTabBarView(
children: <Widget>[
const ListWidget(
'Tab1',
scrollDirection: Axis.horizontal,
),
const ListWidget(
'Tab1',
scrollDirection: Axis.horizontal,
),
],
controller: tabController,
scrollDirection: Axis.vertical,
),
)
],
)
缓存范围
/// cache page count
/// default is 0.
/// if cacheExtent is 1, it has two pages in cache
final int cacheExtent;
ExtendedTabBarView(
children: <Widget>[
List("Tab000"),
List("Tab001"),
List("Tab002"),
List("Tab003"),
],
controller: tabController2,
linkWithAncestor: true,
cacheExtent: 1,
)