72 lines
2.4 KiB
Dart
72 lines
2.4 KiB
Dart
import 'package:flutter/material.dart';
|
||
import 'package:get/get.dart';
|
||
import '../constants/app_constants.dart';
|
||
import '../services/get/theme_controller.dart';
|
||
|
||
/// 时间: 2026-03-22
|
||
/// 功能: 主导航内「标题 + Tab」共用 AppBar 构造
|
||
/// 介绍: 压缩工具栏与 Tab 行高度,关闭 M3 卷动 surface tint,统一收藏页与发现页顶部观感
|
||
/// 最新变化: 2026-04-02 支持深色模式
|
||
|
||
/// 主导航子页(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,
|
||
Color? backgroundColor,
|
||
Color? foregroundColor,
|
||
}) {
|
||
final isDark = backgroundColor != null && backgroundColor != Colors.white;
|
||
final themeController = Get.find<ThemeController>();
|
||
final primaryColor = themeController.currentThemeColor;
|
||
|
||
return AppBar(
|
||
title: Text(
|
||
title,
|
||
style: TextStyle(
|
||
fontWeight: FontWeight.bold,
|
||
fontSize: 18,
|
||
color: foregroundColor ?? (isDark ? Colors.white : Colors.black87),
|
||
),
|
||
),
|
||
backgroundColor: backgroundColor ?? Colors.white,
|
||
foregroundColor:
|
||
foregroundColor ?? (isDark ? Colors.white : Colors.black87),
|
||
iconTheme: IconThemeData(
|
||
color: foregroundColor ?? (isDark ? Colors.white : Colors.black87),
|
||
),
|
||
elevation: 0,
|
||
scrolledUnderElevation: 0,
|
||
surfaceTintColor: Colors.transparent,
|
||
shadowColor: Colors.transparent,
|
||
centerTitle: true,
|
||
leading: leading,
|
||
actions: actions,
|
||
bottom: TabBar(
|
||
controller: tabController,
|
||
isScrollable: tabBarScrollable,
|
||
padding: tabPadding,
|
||
labelPadding: tabLabelPadding,
|
||
tabAlignment: tabBarScrollable ? TabAlignment.start : null,
|
||
dividerHeight: 0,
|
||
dividerColor: Colors.transparent,
|
||
tabs: tabLabels.map((String e) => Tab(text: e)).toList(),
|
||
labelColor: primaryColor,
|
||
unselectedLabelColor: isDark ? Colors.grey[400] : Colors.grey[600],
|
||
indicator: UnderlineTabIndicator(
|
||
borderSide: BorderSide(color: primaryColor, width: 3),
|
||
),
|
||
labelStyle: const TextStyle(fontWeight: FontWeight.bold),
|
||
),
|
||
);
|
||
}
|
||
}
|