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,
      ),
    );
  }
}
相关推荐
AsiaLYF1 小时前
kotlin中MutableStateFlow和MutableSharedFlow的区别是什么?
android·开发语言·kotlin
2501_916008891 小时前
iOS 发布全流程详解,从开发到上架的流程与跨平台使用 开心上架 发布实战
android·macos·ios·小程序·uni-app·cocoa·iphone
4Forsee2 小时前
【Android】浅析 Android 的 IPC 跨进程通信机制
android·java
叶羽西2 小时前
如何区分Android、Android Automotive、Android Auto
android
用户2018792831672 小时前
用 “奶茶店订单系统” 讲懂 MVI 架构
android
LiuYaoheng3 小时前
【Android】布局优化:include、merge、ViewStub的使用及注意事项
android·java
未来猫咪花3 小时前
Riverpod 3.0:一个过度设计的反面教材
flutter
Kapaseker3 小时前
Kotlin Flow 的 emit 和 tryEmit 有什么区别
android·kotlin
消失的旧时光-19434 小时前
Flutter 并发编程全解:从零掌握 Isolate
flutter
好好学习啊天天向上4 小时前
Android Studio 撕开安卓手机投屏
android·智能手机·android studio