|
@@ -5,6 +5,7 @@ import 'package:flutter/widgets.dart';
|
|
import 'package:cs_resources/generated/assets.dart';
|
|
import 'package:cs_resources/generated/assets.dart';
|
|
import 'package:cs_resources/constants/color_constants.dart';
|
|
import 'package:cs_resources/constants/color_constants.dart';
|
|
import 'package:router/ext/auto_router_extensions.dart';
|
|
import 'package:router/ext/auto_router_extensions.dart';
|
|
|
|
+import 'package:widgets/ext/ex_widget.dart';
|
|
import 'my_load_image.dart';
|
|
import 'my_load_image.dart';
|
|
import 'search_app_bar.dart';
|
|
import 'search_app_bar.dart';
|
|
|
|
|
|
@@ -16,31 +17,35 @@ class MyAppBar {
|
|
double? backIconWidth,
|
|
double? backIconWidth,
|
|
double? backIconHeight,
|
|
double? backIconHeight,
|
|
String? subTitle,
|
|
String? subTitle,
|
|
- Color? subTitleColor,
|
|
|
|
- Color textColor = Colors.white,
|
|
|
|
Color backgroundColor = Colors.transparent,
|
|
Color backgroundColor = Colors.transparent,
|
|
SystemUiOverlayStyle? systemUiOverlayStyle,
|
|
SystemUiOverlayStyle? systemUiOverlayStyle,
|
|
|
|
+ bool showBottomDivider = false,
|
|
List<Widget>? actions}) {
|
|
List<Widget>? actions}) {
|
|
|
|
+ // 检查当前主题是亮色还是暗色
|
|
|
|
+ final bool isDarkMode = Theme.of(context).brightness == Brightness.dark;
|
|
|
|
+
|
|
return AppBar(
|
|
return AppBar(
|
|
//设置变色与背景颜色一致,避免滚动的时候AppBar变色
|
|
//设置变色与背景颜色一致,避免滚动的时候AppBar变色
|
|
backgroundColor: backgroundColor,
|
|
backgroundColor: backgroundColor,
|
|
surfaceTintColor: backgroundColor,
|
|
surfaceTintColor: backgroundColor,
|
|
systemOverlayStyle: systemUiOverlayStyle,
|
|
systemOverlayStyle: systemUiOverlayStyle,
|
|
- leading: IconButton(
|
|
|
|
- icon: MyAssetImage(backIconPath ?? Assets.baseLibWhiteBack, width: backIconWidth ?? 11, height: backIconHeight ?? 18),
|
|
|
|
- onPressed: () {
|
|
|
|
- if (backCallback != null) {
|
|
|
|
- backCallback();
|
|
|
|
- } else {
|
|
|
|
- appRouter.maybePop();
|
|
|
|
- }
|
|
|
|
- },
|
|
|
|
- ),
|
|
|
|
|
|
+ // 如果没有自带的返回按钮,直接使用系统自带的返回图标
|
|
|
|
+ leading: backIconPath != null
|
|
|
|
+ ? IconButton(
|
|
|
|
+ icon: MyAssetImage(
|
|
|
|
+ backIconPath,
|
|
|
|
+ width: backIconWidth ?? 11,
|
|
|
|
+ height: backIconHeight ?? 18,
|
|
|
|
+ ),
|
|
|
|
+ onPressed: backCallback,
|
|
|
|
+ )
|
|
|
|
+ : null,
|
|
|
|
+ iconTheme: IconThemeData(color: isDarkMode ? Colors.white : Theme.of(context).colorScheme.primary),
|
|
centerTitle: true,
|
|
centerTitle: true,
|
|
title: subTitle == null
|
|
title: subTitle == null
|
|
? Text(
|
|
? Text(
|
|
title,
|
|
title,
|
|
- style: const TextStyle(color: Colors.white, fontSize: 18, fontWeight: FontWeight.w500),
|
|
|
|
|
|
+ style: TextStyle(color: isDarkMode ? Colors.white : Colors.black, fontSize: 17, fontWeight: FontWeight.w500),
|
|
)
|
|
)
|
|
: Column(
|
|
: Column(
|
|
mainAxisSize: MainAxisSize.max,
|
|
mainAxisSize: MainAxisSize.max,
|
|
@@ -49,64 +54,65 @@ class MyAppBar {
|
|
children: [
|
|
children: [
|
|
Text(
|
|
Text(
|
|
title,
|
|
title,
|
|
- style: const TextStyle(color: Colors.white, fontSize: 18, fontWeight: FontWeight.w500),
|
|
|
|
|
|
+ style: TextStyle(color: isDarkMode ? Colors.white : Colors.black, fontSize: 17, fontWeight: FontWeight.w500),
|
|
),
|
|
),
|
|
Text(
|
|
Text(
|
|
subTitle,
|
|
subTitle,
|
|
- style: TextStyle(color: subTitleColor ?? Colors.white, fontSize: 15, fontWeight: FontWeight.w400),
|
|
|
|
|
|
+ style: TextStyle(color: isDarkMode ? Colors.white : Colors.black, fontSize: 15, fontWeight: FontWeight.w400),
|
|
)
|
|
)
|
|
],
|
|
],
|
|
),
|
|
),
|
|
actions: actions,
|
|
actions: actions,
|
|
elevation: 0.0,
|
|
elevation: 0.0,
|
|
- bottom: const PreferredSize(
|
|
|
|
- preferredSize: Size.fromHeight(0.5),
|
|
|
|
- child: Divider(
|
|
|
|
- height: 0.5,
|
|
|
|
- indent: 0.0,
|
|
|
|
- color: ColorConstants.dividerBar,
|
|
|
|
- )),
|
|
|
|
|
|
+ bottom: showBottomDivider // 根据变量控制 bottom 的显示
|
|
|
|
+ ? const PreferredSize(
|
|
|
|
+ preferredSize: Size.fromHeight(0.5),
|
|
|
|
+ child: Divider(
|
|
|
|
+ height: 0.5,
|
|
|
|
+ indent: 0.0,
|
|
|
|
+ color: ColorConstants.dividerBar,
|
|
|
|
+ ))
|
|
|
|
+ : null,
|
|
);
|
|
);
|
|
}
|
|
}
|
|
|
|
|
|
- //自定义高度快
|
|
|
|
- static SizedBox rowHeight({double height = 30}) {
|
|
|
|
- return SizedBox(height: height);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- //自定义宽度快
|
|
|
|
- static SizedBox rowWidth({double width = 30}) {
|
|
|
|
- return SizedBox(width: width);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
/// 带搜索的AppBar
|
|
/// 带搜索的AppBar
|
|
- static AppBar appSearchBar(BuildContext context,
|
|
|
|
|
|
+ static AppBar searchAppBar(BuildContext context,
|
|
{void Function()? backCallback,
|
|
{void Function()? backCallback,
|
|
String? value,
|
|
String? value,
|
|
String? hintText,
|
|
String? hintText,
|
|
- Color textColor = Colors.white,
|
|
|
|
|
|
+ String? backIconPath,
|
|
|
|
+ double? backIconWidth,
|
|
|
|
+ double? backIconHeight,
|
|
|
|
+ Color textColor = Colors.black,
|
|
Color backgroundColor = Colors.transparent,
|
|
Color backgroundColor = Colors.transparent,
|
|
ValueChanged<String>? onSearch,
|
|
ValueChanged<String>? onSearch,
|
|
ValueChanged<String>? onChanged,
|
|
ValueChanged<String>? onChanged,
|
|
SystemUiOverlayStyle? systemUiOverlayStyle,
|
|
SystemUiOverlayStyle? systemUiOverlayStyle,
|
|
TextEditingController? controller,
|
|
TextEditingController? controller,
|
|
|
|
+ bool showBottomDivider = false,
|
|
List<Widget>? actions}) {
|
|
List<Widget>? actions}) {
|
|
|
|
+ // 检查当前主题是亮色还是暗色
|
|
|
|
+ final bool isDarkMode = Theme.of(context).brightness == Brightness.dark;
|
|
|
|
+
|
|
return AppBar(
|
|
return AppBar(
|
|
backgroundColor: backgroundColor,
|
|
backgroundColor: backgroundColor,
|
|
surfaceTintColor: backgroundColor,
|
|
surfaceTintColor: backgroundColor,
|
|
systemOverlayStyle: systemUiOverlayStyle,
|
|
systemOverlayStyle: systemUiOverlayStyle,
|
|
// 标题与其他控件的间隔
|
|
// 标题与其他控件的间隔
|
|
titleSpacing: 0,
|
|
titleSpacing: 0,
|
|
- leading: IconButton(
|
|
|
|
- icon: const MyAssetImage(Assets.baseLibWhiteBack, width: 11, height: 18),
|
|
|
|
- onPressed: () {
|
|
|
|
- if (backCallback != null) {
|
|
|
|
- backCallback();
|
|
|
|
- } else {
|
|
|
|
- appRouter.maybePop();
|
|
|
|
- }
|
|
|
|
- },
|
|
|
|
- ),
|
|
|
|
|
|
+ // 如果没有自带的返回按钮,直接使用系统自带的返回图标
|
|
|
|
+ leading: backIconPath != null
|
|
|
|
+ ? IconButton(
|
|
|
|
+ icon: MyAssetImage(
|
|
|
|
+ backIconPath,
|
|
|
|
+ width: backIconWidth ?? 11,
|
|
|
|
+ height: backIconHeight ?? 18,
|
|
|
|
+ ),
|
|
|
|
+ onPressed: backCallback,
|
|
|
|
+ )
|
|
|
|
+ : null,
|
|
|
|
+ iconTheme: IconThemeData(color: isDarkMode ? Colors.white : Theme.of(context).colorScheme.primary),
|
|
centerTitle: true,
|
|
centerTitle: true,
|
|
title: SearchAppBar(
|
|
title: SearchAppBar(
|
|
onSearch: onSearch,
|
|
onSearch: onSearch,
|
|
@@ -117,13 +123,15 @@ class MyAppBar {
|
|
),
|
|
),
|
|
actions: actions,
|
|
actions: actions,
|
|
elevation: 0.0,
|
|
elevation: 0.0,
|
|
- bottom: const PreferredSize(
|
|
|
|
- preferredSize: Size.fromHeight(0.5),
|
|
|
|
- child: Divider(
|
|
|
|
- height: 0.5,
|
|
|
|
- indent: 0.0,
|
|
|
|
- color: ColorConstants.dividerBar,
|
|
|
|
- )),
|
|
|
|
|
|
+ bottom: showBottomDivider // 根据变量控制 bottom 的显示
|
|
|
|
+ ? const PreferredSize(
|
|
|
|
+ preferredSize: Size.fromHeight(0.5),
|
|
|
|
+ child: Divider(
|
|
|
|
+ height: 0.5,
|
|
|
|
+ indent: 0.0,
|
|
|
|
+ color: ColorConstants.dividerBar,
|
|
|
|
+ ))
|
|
|
|
+ : null,
|
|
);
|
|
);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -136,14 +144,14 @@ class MyAppBar {
|
|
double? backIconWidth,
|
|
double? backIconWidth,
|
|
double? backIconHeight,
|
|
double? backIconHeight,
|
|
String? subTitle,
|
|
String? subTitle,
|
|
- Color? subTitleColor,
|
|
|
|
- bool needBottomDivider = true,
|
|
|
|
- Color textColor = Colors.white,
|
|
|
|
Color backgroundColor = Colors.transparent,
|
|
Color backgroundColor = Colors.transparent,
|
|
|
|
+ bool showBottomDivider = false,
|
|
List<Widget>? actions,
|
|
List<Widget>? actions,
|
|
}) {
|
|
}) {
|
|
// 计算左侧和右侧固定容器的宽度
|
|
// 计算左侧和右侧固定容器的宽度
|
|
double sideWidth = 55;
|
|
double sideWidth = 55;
|
|
|
|
+ // 检查当前主题是亮色还是暗色
|
|
|
|
+ final bool isDarkMode = Theme.of(context).brightness == Brightness.dark;
|
|
|
|
|
|
return Column(
|
|
return Column(
|
|
children: [
|
|
children: [
|
|
@@ -160,20 +168,31 @@ class MyAppBar {
|
|
child: Container(
|
|
child: Container(
|
|
width: sideWidth,
|
|
width: sideWidth,
|
|
alignment: Alignment.center,
|
|
alignment: Alignment.center,
|
|
- child: IconButton(
|
|
|
|
- icon: MyAssetImage(
|
|
|
|
- backIconPath ?? Assets.baseLibWhiteBack,
|
|
|
|
- width: backIconWidth ?? 11,
|
|
|
|
- height: backIconHeight ?? 18,
|
|
|
|
- ),
|
|
|
|
- onPressed: () {
|
|
|
|
- if (backCallback != null) {
|
|
|
|
- backCallback();
|
|
|
|
- } else {
|
|
|
|
- appRouter.maybePop();
|
|
|
|
- }
|
|
|
|
- },
|
|
|
|
- ),
|
|
|
|
|
|
+ child: backIconPath != null
|
|
|
|
+ ? IconButton(
|
|
|
|
+ icon: MyAssetImage(
|
|
|
|
+ backIconPath,
|
|
|
|
+ width: backIconWidth ?? 11,
|
|
|
|
+ height: backIconHeight ?? 18,
|
|
|
|
+ ),
|
|
|
|
+ onPressed: () {
|
|
|
|
+ if (backCallback != null) {
|
|
|
|
+ backCallback();
|
|
|
|
+ } else {
|
|
|
|
+ appRouter.maybePop();
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ )
|
|
|
|
+ : BackButton(
|
|
|
|
+ color: isDarkMode ? Colors.white : Theme.of(context).colorScheme.primary,
|
|
|
|
+ onPressed: () {
|
|
|
|
+ if (backCallback != null) {
|
|
|
|
+ backCallback();
|
|
|
|
+ } else {
|
|
|
|
+ appRouter.maybePop();
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ ),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
// 标题在中间
|
|
// 标题在中间
|
|
@@ -186,7 +205,7 @@ class MyAppBar {
|
|
child: subTitle == null
|
|
child: subTitle == null
|
|
? Text(
|
|
? Text(
|
|
title,
|
|
title,
|
|
- style: TextStyle(color: textColor, fontSize: 18, fontWeight: FontWeight.w500),
|
|
|
|
|
|
+ style: TextStyle(color: isDarkMode ? Colors.white : Colors.black, fontSize: 17, fontWeight: FontWeight.w500),
|
|
overflow: TextOverflow.ellipsis,
|
|
overflow: TextOverflow.ellipsis,
|
|
)
|
|
)
|
|
: Column(
|
|
: Column(
|
|
@@ -196,12 +215,12 @@ class MyAppBar {
|
|
children: [
|
|
children: [
|
|
Text(
|
|
Text(
|
|
title,
|
|
title,
|
|
- style: TextStyle(color: textColor, fontSize: 18, fontWeight: FontWeight.w500),
|
|
|
|
|
|
+ style: TextStyle(color: isDarkMode ? Colors.white : Colors.black, fontSize: 17, fontWeight: FontWeight.w500),
|
|
overflow: TextOverflow.ellipsis,
|
|
overflow: TextOverflow.ellipsis,
|
|
),
|
|
),
|
|
Text(
|
|
Text(
|
|
- subTitle!,
|
|
|
|
- style: TextStyle(color: subTitleColor ?? textColor, fontSize: 15, fontWeight: FontWeight.w400),
|
|
|
|
|
|
+ subTitle,
|
|
|
|
+ style: TextStyle(color: isDarkMode ? Colors.white : Colors.black, fontSize: 15, fontWeight: FontWeight.w400),
|
|
),
|
|
),
|
|
],
|
|
],
|
|
),
|
|
),
|
|
@@ -225,8 +244,8 @@ class MyAppBar {
|
|
),
|
|
),
|
|
),
|
|
),
|
|
// 底部的分割线
|
|
// 底部的分割线
|
|
- if (needBottomDivider)
|
|
|
|
- Divider(
|
|
|
|
|
|
+ if (showBottomDivider)
|
|
|
|
+ const Divider(
|
|
height: 0.5,
|
|
height: 0.5,
|
|
color: ColorConstants.dividerBar,
|
|
color: ColorConstants.dividerBar,
|
|
),
|
|
),
|
|
@@ -235,18 +254,24 @@ class MyAppBar {
|
|
}
|
|
}
|
|
|
|
|
|
/// 当前App中的自定义TitleBar用于沉浸式处理,不是用在 Scaffold 下面的,直接放在 Column 下面即可
|
|
/// 当前App中的自定义TitleBar用于沉浸式处理,不是用在 Scaffold 下面的,直接放在 Column 下面即可
|
|
- static Widget searchTitleBar(BuildContext context, {
|
|
|
|
|
|
+ static Widget searchTitleBar(
|
|
|
|
+ BuildContext context, {
|
|
void Function()? backCallback,
|
|
void Function()? backCallback,
|
|
String? value,
|
|
String? value,
|
|
String? hintText,
|
|
String? hintText,
|
|
- Color textColor = Colors.white,
|
|
|
|
|
|
+ String? backIconPath,
|
|
|
|
+ double? backIconWidth,
|
|
|
|
+ double? backIconHeight,
|
|
Color backgroundColor = Colors.transparent,
|
|
Color backgroundColor = Colors.transparent,
|
|
ValueChanged<String>? onSearch,
|
|
ValueChanged<String>? onSearch,
|
|
ValueChanged<String>? onChanged,
|
|
ValueChanged<String>? onChanged,
|
|
- bool needBottomDivider = true,
|
|
|
|
TextEditingController? controller,
|
|
TextEditingController? controller,
|
|
|
|
+ bool showBottomDivider = false,
|
|
List<Widget>? actions,
|
|
List<Widget>? actions,
|
|
}) {
|
|
}) {
|
|
|
|
+ // 检查当前主题是亮色还是暗色
|
|
|
|
+ final bool isDarkMode = Theme.of(context).brightness == Brightness.dark;
|
|
|
|
+
|
|
return Column(
|
|
return Column(
|
|
children: [
|
|
children: [
|
|
Container(
|
|
Container(
|
|
@@ -259,20 +284,31 @@ class MyAppBar {
|
|
Container(
|
|
Container(
|
|
width: 55,
|
|
width: 55,
|
|
alignment: Alignment.center,
|
|
alignment: Alignment.center,
|
|
- child: IconButton(
|
|
|
|
- icon: MyAssetImage(
|
|
|
|
- Assets.baseLibWhiteBack,
|
|
|
|
- width: 11,
|
|
|
|
- height: 18,
|
|
|
|
- ),
|
|
|
|
- onPressed: () {
|
|
|
|
- if (backCallback != null) {
|
|
|
|
- backCallback();
|
|
|
|
- } else {
|
|
|
|
- appRouter.maybePop();
|
|
|
|
- }
|
|
|
|
- },
|
|
|
|
- ),
|
|
|
|
|
|
+ child: backIconPath != null
|
|
|
|
+ ? IconButton(
|
|
|
|
+ icon: MyAssetImage(
|
|
|
|
+ backIconPath,
|
|
|
|
+ width: backIconWidth ?? 11,
|
|
|
|
+ height: backIconHeight ?? 18,
|
|
|
|
+ ),
|
|
|
|
+ onPressed: () {
|
|
|
|
+ if (backCallback != null) {
|
|
|
|
+ backCallback();
|
|
|
|
+ } else {
|
|
|
|
+ appRouter.maybePop();
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ )
|
|
|
|
+ : BackButton(
|
|
|
|
+ color: isDarkMode ? Colors.white : Theme.of(context).colorScheme.primary,
|
|
|
|
+ onPressed: () {
|
|
|
|
+ if (backCallback != null) {
|
|
|
|
+ backCallback();
|
|
|
|
+ } else {
|
|
|
|
+ appRouter.maybePop();
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ ),
|
|
),
|
|
),
|
|
// 搜索栏
|
|
// 搜索栏
|
|
Expanded(
|
|
Expanded(
|
|
@@ -296,7 +332,7 @@ class MyAppBar {
|
|
),
|
|
),
|
|
),
|
|
),
|
|
// 底部的分割线
|
|
// 底部的分割线
|
|
- if (needBottomDivider)
|
|
|
|
|
|
+ if (showBottomDivider)
|
|
const Divider(
|
|
const Divider(
|
|
height: 0.5,
|
|
height: 0.5,
|
|
indent: 0.0,
|
|
indent: 0.0,
|
|
@@ -305,6 +341,4 @@ class MyAppBar {
|
|
],
|
|
],
|
|
);
|
|
);
|
|
}
|
|
}
|
|
-
|
|
|
|
-
|
|
|
|
}
|
|
}
|