ChipTabSwitcher class

A horizontally scrollable chip-style tab switcher.

Works with either:

  1. An explicit controller, or
  2. A surrounding DefaultTabController.

Example with DefaultTabController:

const terms = ['114-2', '114-1', '113-2'];

DefaultTabController(
  length: terms.length,
  child: Scaffold(
    appBar: AppBar(
      title: const ChipTabSwitcher(tabs: terms),
    ),
    body: TabBarView(
      children: [
        for (final term in terms) Center(child: Text(term)),
      ],
    ),
  ),
)

Example with an external TabController:

class TermSwitcherExample extends StatefulWidget {
  const TermSwitcherExample({super.key});

  @override
  State<TermSwitcherExample> createState() => _TermSwitcherExampleState();
}

class _TermSwitcherExampleState extends State<TermSwitcherExample>
    with SingleTickerProviderStateMixin {
  static const terms = ['A', 'B', 'C'];
  late final TabController _controller;

  @override
  void initState() {
    super.initState();
    _controller = TabController(length: terms.length, vsync: this);
  }

  @override
  void dispose() {
    _controller.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        ChipTabSwitcher(
          tabs: terms,
          controller: _controller,
        ),
        Expanded(
          child: TabBarView(
            controller: _controller,
            children: [
              for (final term in terms) Center(child: Text(term)),
            ],
          ),
        ),
      ],
    );
  }
}
Inheritance

Constructors

ChipTabSwitcher({Key? key, required List<String> tabs, TabController? controller, ValueChanged<int>? onReselected, EdgeInsetsGeometry padding = const EdgeInsets.symmetric(horizontal: 16), double spacing = 8})
const

Properties

controller → TabController?
final
hashCode → int
The hash code for this object.
no setterinherited
key → Key?
Controls how one widget replaces another widget in the tree.
finalinherited
onReselected → ValueChanged<int>?
Called when the currently active tab is tapped again.
final
padding → EdgeInsetsGeometry
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
spacing → double
final
tabs → List<String>
final

Methods

createElement() → StatefulElement
Creates a StatefulElement to manage this widget's location in the tree.
inherited
createState() → State<ChipTabSwitcher>
Creates the mutable state for this widget at a given location in the tree.
override
debugDescribeChildren() → List<DiagnosticsNode>
Returns a list of DiagnosticsNode objects describing this node's children.
inherited
debugFillProperties(DiagnosticPropertiesBuilder properties) → void
Add additional properties associated with the node.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toDiagnosticsNode({String? name, DiagnosticsTreeStyle? style}) → DiagnosticsNode
Returns a debug representation of the object that is used by debugging tools and by DiagnosticsNode.toStringDeep.
inherited
toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) → String
A string representation of this object.
inherited
toStringDeep({String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug, int wrapWidth = 65}) → String
Returns a string representation of this node and its descendants.
inherited
toStringShallow({String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) → String
Returns a one-line detailed description of the object.
inherited
toStringShort() → String
A short, textual description of this widget.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited