indicator_tab_bar library
A fixed-width tab indicator, and a sliver AnimatedSwitcher for the body each tab selects.
LineTabIndicator goes on TabBar.indicator and draws a short bar of a
set width centred under the tab, rather than one stretched across the tab
or across its label:
TabBar(
indicatorSize: TabBarIndicatorSize.label,
indicator: const LineTabIndicator(
color: Color(0xFF2F6BFF),
strokeWidth: 3,
indicatorWidth: 20,
radius: 4,
),
tabs: const [Tab(text: 'Spot'), Tab(text: 'Futures')],
)
SliverAnimatedSwitcher cross-fades what that tab reveals, when the body
is a sliver inside a CustomScrollView rather than a box:
SliverAnimatedSwitcher(
child: SliverList.list(key: ValueKey(tab), children: rows),
)
Nothing here imports Material. TabBar.indicator takes a plain
Decoration, so the indicator works the same whether the TabBar comes
from package:flutter/material.dart or from the material_ui fork.
Classes
- LineTabIndicator
-
A Decoration for
TabBar.indicatorthat draws a short bar of a fixed width, by default centred under the tab, instead of one stretched across it. - SliverAnimatedSwitcher
-
An AnimatedSwitcher for slivers: swap child for another sliver and the
new one fades in, in place, inside a
CustomScrollView.
Typedefs
-
SliverAnimatedSwitcherTransitionBuilder
= Widget Function(Widget sliver, Animation<
double> animation) - Builds the transition wrapped around an incoming sliver.