Initial commit: Flutter 无书应用项目
This commit is contained in:
67
lib/widgets/tabbed_nav_app_bar.dart
Normal file
67
lib/widgets/tabbed_nav_app_bar.dart
Normal file
@@ -0,0 +1,67 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import '../constants/app_constants.dart';
|
||||
|
||||
/// 时间: 2026-03-22
|
||||
/// 功能: 主导航内「标题 + Tab」共用 AppBar 构造
|
||||
/// 介绍: 压缩工具栏与 Tab 行高度,关闭 M3 卷动 surface tint,统一收藏页与发现页顶部观感
|
||||
/// 最新变化: 初始提取,减少两页相同结构的顶部留白
|
||||
|
||||
/// 主导航子页(IndexedStack 内)带 [TabBar] 的页面共用 [AppBar] 配置
|
||||
class TabbedNavAppBar {
|
||||
TabbedNavAppBar._();
|
||||
|
||||
static AppBar build({
|
||||
required String title,
|
||||
required TabController tabController,
|
||||
required List<String> tabLabels,
|
||||
List<Widget>? actions,
|
||||
Widget? leading,
|
||||
bool tabBarScrollable = false,
|
||||
EdgeInsetsGeometry? tabPadding,
|
||||
EdgeInsetsGeometry? tabLabelPadding,
|
||||
}) {
|
||||
return AppBar(
|
||||
toolbarHeight: AppConstants.tabbedPageToolbarHeight,
|
||||
title: Text(title, style: const TextStyle(fontWeight: FontWeight.bold)),
|
||||
backgroundColor: Colors.white,
|
||||
foregroundColor: Colors.black87,
|
||||
iconTheme: const IconThemeData(color: Colors.black87),
|
||||
elevation: 0,
|
||||
scrolledUnderElevation: 0,
|
||||
surfaceTintColor: Colors.transparent,
|
||||
shadowColor: Colors.transparent,
|
||||
centerTitle: true,
|
||||
leading: leading,
|
||||
actions: actions,
|
||||
// 用 PreferredSize + 固定高度略小于默认 Tab 行,减少两页相同的「标题+Tab」总高度(当前 SDK 无 tabHeight 参数)
|
||||
bottom: PreferredSize(
|
||||
preferredSize: Size.fromHeight(AppConstants.tabbedPageTabBarHeight),
|
||||
child: SizedBox(
|
||||
height: AppConstants.tabbedPageTabBarHeight,
|
||||
child: TabBar(
|
||||
controller: tabController,
|
||||
isScrollable: tabBarScrollable,
|
||||
padding:
|
||||
tabPadding ??
|
||||
(tabBarScrollable
|
||||
? const EdgeInsets.only(
|
||||
left: AppConstants.pageHorizontalPadding,
|
||||
right: 8,
|
||||
)
|
||||
: null),
|
||||
labelPadding: tabLabelPadding,
|
||||
tabAlignment: tabBarScrollable ? TabAlignment.start : null,
|
||||
dividerHeight: 0,
|
||||
dividerColor: Colors.transparent,
|
||||
tabs: tabLabels.map((String e) => Tab(text: e)).toList(),
|
||||
labelColor: AppConstants.primaryColor,
|
||||
unselectedLabelColor: Colors.grey[600],
|
||||
indicatorColor: AppConstants.primaryColor,
|
||||
indicatorWeight: 3,
|
||||
labelStyle: const TextStyle(fontWeight: FontWeight.bold),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user