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,
      ),
    );
  }
}
相关推荐
用户02738518402610 小时前
[Android]RecycleView的item用法
android
humiaor11 小时前
Flutter之riverpod状态管理Widget UI详解
flutter·consumer·widget·hooks·provider·riverpod·hookwidget
农夫三拳_有点甜11 小时前
Flutter Stack 组件总结
flutter
前行的小黑炭11 小时前
Android :为APK注入“脂肪”,论Android垃圾代码在安全加固中的作用
android·kotlin
帅得不敢出门12 小时前
Docker安装Ubuntu搭建Android SDK编译环境
android·ubuntu·docker
MaoJiu12 小时前
Flutter混合开发:在iOS工程中嵌入Flutter Module
flutter·ios
tangweiguo0305198712 小时前
Android Kotlin 动态注册 Broadcast 的完整封装方案
android·kotlin
fatiaozhang952713 小时前
浪潮CD1000-移动云电脑-RK3528芯片-2+32G-安卓9-2种开启ADB ROOT刷机教程方法
android·网络·adb·电脑·电视盒子·刷机固件·机顶盒刷机
前行的小黑炭13 小时前
Android 不同构建模式下使用不同类的例子:如何在debug模式和release模式,让其使用不同的类呢?
android·kotlin·gradle
andyguo14 小时前
AI模型测评平台工程化实战十二讲(第一讲:从手工测试到系统化的觉醒)
android