TabController constructor Null safety

TabController(
  1. {int initialIndex = 0,
  2. required int length,
  3. required TickerProvider vsync}
)

Creates an object that manages the state required by TabBar and a TabBarView.

The length must not be null or negative. Typically it's a value greater than one, i.e. typically there are two or more tabs. The length must match TabBar.tabs's and TabBarView.children's length.

The initialIndex must be valid given length and must not be null. If length is zero, then initialIndex must be 0 (the default).

Implementation

TabController({ int initialIndex = 0, required this.length, required TickerProvider vsync })
  : assert(length != null && length >= 0),
    assert(initialIndex != null && initialIndex >= 0 && (length == 0 || initialIndex < length)),
    _index = initialIndex,
    _previousIndex = initialIndex,
    _animationController = AnimationController.unbounded(
      value: initialIndex.toDouble(),
      vsync: vsync,
    );