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,
      ),
    );
  }
}
相关推荐
j***827028 分钟前
【MyBatisPlus】MyBatisPlus介绍与使用
android·前端·后端
ljt272496066141 分钟前
Compose笔记(五十八)--LinearOutSlowInEasing
android·笔记·android jetpack
q***484144 分钟前
Redis Desktop Manager(Redis可视化工具)安装及使用详细教程
android·前端·后端
灰灰勇闯IT1 小时前
flutter环境配置中遇到的问题
flutter
renxhui1 小时前
Dart 速通攻略(面向 Android 工程师)
android·flutter·dart
Frank_HarmonyOS1 小时前
MVI模式
android
m***9821 小时前
Redis6.2.6下载和安装
android·前端·后端
未来之窗软件服务1 小时前
幽冥大陆(三十九)php二维数组去重——东方仙盟筑基期
android·开发语言·算法·php·仙盟创梦ide·东方仙盟·东方仙盟sdk
w***4242 小时前
【mysql部署】在ubuntu22.04上安装和配置mysql教程
android·mysql·adb
e***75392 小时前
MySQL错误-this is incompatible with sql_mode=only_full_group_by完美解决方案
android·sql·mysql