Flutter 顶部导航标签组件Tab + TabBar + TabController

Tab定义标题

TabBarView定义内容区域

TabController 控制切换

TabBar

属性 说明
isScrollable tab是否可滑动
indicatorColor 指示器的颜色
indicatorWeight 指示器的高度
labelColor 选中tab的颜色
unselectedLabelColor 选中tab的颜色
dart 复制代码
class MyState extends State {
  @override
  Widget build(BuildContext context) {
    TabBar tabBar = TabBar(
      unselectedLabelColor: Colors.cyan,
      labelColor: Colors.green ,
      indicatorColor: Colors.blue,
      indicatorWeight: 10,
      isScrollable: true,
      tabs: [
        Tab(icon: Icon(Icons.account_circle), text: "首页"),
        Tab(icon: Icon(Icons.account_circle), text: "视频"),
        Tab(icon: Icon(Icons.account_circle), text: "消息"),
        Tab(icon: Icon(Icons.account_circle), text: "购物"),
        Tab(icon: Icon(Icons.account_circle), text: "我的"),
      ],
    );

    TabBarView tabBarView = TabBarView(
      children: [
        Center(child: Text("首页")),
        Center(child: Text("视频")),
        Center(child: Text("消息")),
        Center(child: Text("购物")),
        Center(child: Text("我的")),
      ],
    );

    return DefaultTabController(
      length: 5,
      child: Scaffold(
        appBar: AppBar(title: Text("购物"), bottom: tabBar),
        body: tabBarView,
      ),
    );
  }
}
相关推荐
alexhilton19 小时前
使用Android Archive进行打包
android·kotlin·android jetpack
badhope20 小时前
做了几年安卓开发,这些坑我帮你踩过了
android·android studio
程序员老刘3 天前
跨平台开发地图 | 2026年6月
flutter·ai编程·客户端
逐光老顽童3 天前
Java 与 Kotlin 混合开发避坑指南:30 个真实案例实录
android·kotlin
爱勇宝3 天前
鸿蒙生态的下半场:开发者不只要能开发,还要能赚钱
android·前端·程序员
Yeyu3 天前
刷新一帧的艺术:invalidate / postInvalidate / postInvalidateOnAnimation全解析
android
潘潘潘4 天前
Android OTA 升级原理和流程介绍
android
悟空瞎说4 天前
Flutter 架构详解:新手必懂底层原理
flutter
SoaringHeart4 天前
Flutter最佳实践:IM聊天文字链接自动识别跳转
前端·flutter
plainGeekDev4 天前
null 判断 → Kotlin 可空类型
android·java·kotlin