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,
      ),
    );
  }
}
相关推荐
雨白24 分钟前
压缩、序列化与哈希
android
安卓开发者1 小时前
RxJava 核心概念解析:构建响应式Android应用的基石
android·echarts·rxjava
叽哥1 小时前
flutter学习第 18 节:设备功能调用
android·flutter·ios
Monkey-旭2 小时前
Android ADB 常用指令全解析
android·adb
丐中丐9993 小时前
Android NFC框架的NfcService与hal层代码概览
android
程序员老刘4 小时前
2025 Google 开发者大会 客户端要点速览
flutter·ai编程·客户端
用户2018792831674 小时前
<include>标签时设置ltr无效?
android
用户2018792831674 小时前
Android多语言与RTL/LTR适配
android
minos.cpp5 小时前
第一章 OkHttp 是怎么发出一个请求的?——整体流程概览
android·okhttp·面试