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,
      ),
    );
  }
}
相关推荐
robotx3 小时前
安卓线程相关
android
消失的旧时光-19433 小时前
Android 面试高频:JSON 文件、大数据存储与断电安全(从原理到工程实践)
android·面试·json
dalancon4 小时前
VSYNC 信号流程分析 (Android 14)
android
dalancon4 小时前
VSYNC 信号完整流程2
android
dalancon4 小时前
SurfaceFlinger 上帧后 releaseBuffer 完整流程分析
android
用户69371750013845 小时前
不卷AI速度,我卷自己的从容——北京程序员手记
android·前端·人工智能
程序员Android6 小时前
Android 刷新一帧流程trace拆解
android
墨狂之逸才6 小时前
解决 Android/Gradle 编译报错:Comparison method violates its general contract!
android
阿明的小蝴蝶7 小时前
记一次Gradle环境的编译问题与解决
android·前端·gradle
汪海游龙7 小时前
开源项目 Trending AI 招募 Google Play 内测人员(12 名)
android·github