Designing an Expanding Flex Tab Bar in Flutter

Engineering #flutter#ui#open-source

Bottom and top tab bars in mobile apps often hit an awkward trade-off once you have four or five items: either every label gets truncated with an ellipsis, or you drop labels altogether and leave users guessing what each icon means.

The Idea Behind flexible_tab_bar

While working on Flutter UIs, I built flexible_tab_bar around a simple rule:

  • The active tab gets a larger flex weight and expands smoothly to show its icon, full title, and optional count badge.
  • Inactive tabs compact down to their icon (or a condensed label), freeing up horizontal space where it actually matters.

Key Implementation Takeaways

  1. Animate weights, not fixed pixel widths: Hardcoding widths breaks across screen sizes and text scale factors. Interpolating flex allocations keeps the bar responsive on everything from compact phones to tablets.
  2. Clip overflow during transitions: As a tab collapses, its label fades out slightly faster than the container shrinks so text never wraps mid-frame.
  3. Keep badge state independent: Notification badges can appear on collapsed or expanded tabs without shifting baseline alignment.

You can check out the source code on GitHub or install it from pub.dev.