Skip to content

TabIndicatorAnimation

Defines how the tab indicator animates when the selected tab changes.

Inherits: Enum

Properties

  • ELASTIC

    The tab indicator animates with an elastic effect.

  • LINEAR

    The tab indicator animates linearly.

Examples#

Showcase#

import flet as ft


def showcase_card(animation: ft.TabIndicatorAnimation) -> ft.Container:
    tabs_count = 3

    tab_bar = ft.TabBar(
        indicator_animation=animation,
        indicator=ft.UnderlineTabIndicator(
            border_side=ft.BorderSide(width=4, color=ft.Colors.PRIMARY),
            insets=ft.Padding.only(bottom=3),
        ),
        tabs=[
            ft.Tab(label="Home"),
            ft.Tab(label="Search"),
            ft.Tab(label="Profile"),
        ],
    )

    tab_view = ft.Container(
        height=70,
        alignment=ft.Alignment.CENTER,
        border=ft.Border.all(1, ft.Colors.OUTLINE),
        border_radius=8,
        bgcolor=ft.Colors.SURFACE,
        content=ft.TabBarView(
            controls=[
                ft.Container(
                    alignment=ft.Alignment.CENTER,
                    content=ft.Text(f"View {i + 1}"),
                )
                for i in range(tabs_count)
            ]
        ),
    )

    return ft.Container(
        width=360,
        padding=12,
        border=ft.Border.all(1, ft.Colors.RED),
        border_radius=10,
        bgcolor=ft.Colors.SURFACE_CONTAINER_LOW,
        content=ft.Column(
            spacing=8,
            controls=[
                ft.Text(animation.name, weight=ft.FontWeight.BOLD),
                ft.Tabs(
                    length=tabs_count,
                    selected_index=1,
                    content=ft.Column(spacing=8, controls=[tab_bar, tab_view]),
                ),
            ],
        ),
    )


def main(page: ft.Page):
    page.theme_mode = ft.ThemeMode.DARK
    page.horizontal_alignment = ft.CrossAxisAlignment.CENTER

    page.appbar = ft.AppBar(title="TabIndicatorAnimation Showcase")
    page.add(
        ft.Text("Click tabs to compare indicator movement animation."),
        ft.Row(
            wrap=True,
            spacing=12,
            expand=True,
            scroll=ft.ScrollMode.AUTO,
            alignment=ft.MainAxisAlignment.CENTER,
            controls=[
                showcase_card(animation) for animation in ft.TabIndicatorAnimation
            ],
        ),
    )


ft.run(main)

Properties#

ELASTIC = 'elastic' class-attribute instance-attribute #

The tab indicator animates with an elastic effect.

LINEAR = 'linear' class-attribute instance-attribute #

The tab indicator animates linearly.