Flutter TabBar下方白条隐藏

1,718 阅读1分钟

TabBar下划线产生原因

我们在设置AppBar的时候,常常用到TabBar做嵌套导航,但是由于tabbar自带下划线,会使得界面的设计不美观
在这里插入图片描述
这是由于我们在 MaterialApp里面的theme主题管理中开启了 useMaterial3: true ,这会导致TabBar组件样式出现下划线

Tabbar取消下划线

解决的方案有两种

方案一

Themedate里面将useMaterial3设置为false

theme: ThemeData(
            fontFamily: "PingFang",
            colorScheme: ColorScheme.fromSeed(seedColor: Colors.blueGrey),
            useMaterial3: false,
          )

方案二

Themedate里面添加一个属性tabBarTheme ,内容为const TabBarTheme(dividerColor: Colors.transparent)

theme: ThemeData(
            fontFamily: "PingFang",
            colorScheme: ColorScheme.fromSeed(seedColor: Colors.blueGrey),
            useMaterial3: true,
            // 去除TabBar底部线条
            tabBarTheme: const TabBarTheme(dividerColor: Colors.transparent),
          )

效果如下 在这里插入图片描述