How to change background color of TabBar without changing the AppBar in flutter?

amater picture amater · May 28, 2018 · Viewed 44.7k times · Source

How to change background color of TabBar without changing the AppBar? The TabBar does not have a background property, is there a workaround?

Answer

Noor Dawod picture Noor Dawod · Feb 7, 2019

Create a simple Widget for this, cannot be simpler:

class ColoredTabBar extends Container implements PreferredSizeWidget {
  ColoredTabBar(this.color, this.tabBar);

  final Color color;
  final TabBar tabBar;

  @override
  Size get preferredSize => tabBar.preferredSize;

  @override
  Widget build(BuildContext context) => Container(
    color: color,
    child: tabBar,
  );
}