setTabBar method

TabBar setTabBar(
  1. int key,
  2. TabController tabController,
  3. List<Tab> tabList, {
  4. Color indicatorColor = Colors.black,
  5. Color unselectedLabelColor = Colors.white,
  6. Color selectedLabelTextColor = Colors.blue,
  7. Color unselectedLabelTextColor = Colors.white,
  8. Color labelColor = Colors.blue,
})

Creates a customizable TabBar widget with styling options.

Generates a scrollable TabBar with configurable colors, fonts, and alignment. Integrates with a TabController for managing tab state.

Parameters:

  • key: Unique key identifier for the TabBar widget.
  • tabController: Controller managing tab selection and animation.
  • tabList: List of Tab widgets to display.
  • indicatorColor: Color of the selection indicator (defaults to black).
  • unselectedLabelColor: Color for unselected tab labels (defaults to white).
  • selectedLabelTextColor: Color for selected tab text (defaults to blue).
  • unselectedLabelTextColor: Color for unselected tab text (defaults to white).
  • labelColor: Primary color for selected labels (defaults to blue).

Returns a scrollable TabBar with the specified styling.

The TabBar is configured with:

  • Horizontal scrolling enabled
  • Left-aligned tabs
  • Font families from Utils.appConstants
  • Font size from Utils.appConstants.textSubHeaderFontSize

Example:

setTabBar(
  1,
  _tabController,
  [Tab(text: 'Home'), Tab(text: 'Profile')],
  indicatorColor: Colors.blue,
  labelColor: Colors.blue,
);

Implementation

TabBar setTabBar(int key, TabController tabController, List<Tab> tabList,
    {Color indicatorColor = Colors.black,
    Color unselectedLabelColor = Colors.white,
    Color selectedLabelTextColor = Colors.blue,
    Color unselectedLabelTextColor = Colors.white,
    Color labelColor = Colors.blue}) {
  return TabBar(
    isScrollable: true,
    tabAlignment: TabAlignment.start,
    key: ValueKey(key),
    controller: tabController,
    indicatorColor: indicatorColor,
    unselectedLabelColor: unselectedLabelColor,
    labelColor: labelColor,
    labelStyle: TextStyle(
        color: selectedLabelTextColor,
        fontFamily: Utils.appConstants.boldFontFamily,
        fontSize: Utils.appConstants.textSubHeaderFontSize),
    unselectedLabelStyle: TextStyle(
        color: unselectedLabelTextColor,
        fontFamily: Utils.appConstants.boldFontFamily,
        fontSize: Utils.appConstants.textSubHeaderFontSize),
    tabs: tabList,
  );
}