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,
      ),
    );
  }
}
相关推荐
SoaringHeart9 小时前
Flutter最佳实践:用 flutter_html 渲染富文本
前端·flutter
_祝你今天愉快10 小时前
Android 高级绘制:[四] Canvas-实际案例操作
android
三少爷的鞋10 小时前
Android 工程师的技术信仰崩塌史
android
AirDroid_cn13 小时前
Android 15 权限回溯:已授予的麦克风权限如何批量回收?
android
Mr_万能胶13 小时前
官方发布,不烧心的 AOSP 编译提速技巧
android·ci/cd·架构
booboosui14 小时前
安卓 8.1 也能装了:代价是一条黄字和两个静默 bug
android
Ehtan_Zheng17 小时前
Jetpack AppState Transform:让 Compose 的响应式状态走出 UI 层
android
yyuuuzz19 小时前
nginx 502 排查,先看上游超时那一行
android·java·运维·nginx·502
恋猫de小郭1 天前
Flutter 3.50.0 Release 的第一个崩溃,修好了,还没 hotfix
android·前端·flutter
alexhilton1 天前
MVI 让屏幕一次只有一个状态
android·kotlin·android jetpack