From b2ac4c0d5f6f1ef32ac61ba9786c818f69321f87 Mon Sep 17 00:00:00 2001 From: lijuncai <516346556@qq.com> Date: Fri, 17 Feb 2023 15:36:32 +0800 Subject: [PATCH] fix brn_app_bar global style don't work --- lib/src/components/navbar/brn_appbar.dart | 40 ++++++++++----- lib/src/theme/configs/brn_appbar_config.dart | 52 ++++++++++++-------- 2 files changed, 58 insertions(+), 34 deletions(-) diff --git a/lib/src/components/navbar/brn_appbar.dart b/lib/src/components/navbar/brn_appbar.dart index c68cb0e3..a1850534 100644 --- a/lib/src/components/navbar/brn_appbar.dart +++ b/lib/src/components/navbar/brn_appbar.dart @@ -233,8 +233,9 @@ class BrnAppBar extends PreferredSize { } else if (brightness == Brightness.dark) { _defaultConfig = _defaultConfig.merge(BrnAppBarConfig.dark()); } - _defaultConfig = _defaultConfig - .merge(BrnAppBarConfig(backgroundColor: this.backgroundColor, showDefaultBottom: this.showDefaultBottom)); + _defaultConfig = _defaultConfig.merge(BrnAppBarConfig( + backgroundColor: this.backgroundColor, + showDefaultBottom: this.showDefaultBottom)); _defaultConfig = BrnThemeConfigurator.instance .getConfig(configId: _defaultConfig.configId) @@ -259,19 +260,33 @@ class BrnAppBar extends PreferredSize { @override Widget get child { BrnAppBarConfig _defaultConfig = themeData ?? BrnAppBarConfig(); + BrnAppBarConfig globalAppBarConfig = BrnThemeConfigurator.instance + .getConfig(configId: _defaultConfig.configId) + .appBarConfig; + BrnAppBarConfig _appBarConfig = globalAppBarConfig.merge( + BrnAppBarConfig(backgroundColor: backgroundColor), + ); //当外部传入主题 if (brightness == Brightness.light) { - _defaultConfig = _defaultConfig.merge(BrnAppBarConfig.light()); + _appBarConfig = _appBarConfig.merge( + BrnAppBarConfig.light( + titleStyle: globalAppBarConfig.titleStyle, + actionsStyle: globalAppBarConfig.actionsStyle, + leadIconBuilder: globalAppBarConfig.leadIconBuilder, + backgroundColor: backgroundColor, + ), + ); } else if (brightness == Brightness.dark) { - _defaultConfig = _defaultConfig.merge(BrnAppBarConfig.dark()); + _appBarConfig = _appBarConfig.merge( + BrnAppBarConfig.dark( + titleStyle: globalAppBarConfig.titleStyle, + actionsStyle: globalAppBarConfig.actionsStyle, + leadIconBuilder: globalAppBarConfig.leadIconBuilder, + backgroundColor: backgroundColor, + ), + ); } - _defaultConfig = - _defaultConfig.merge(BrnAppBarConfig(backgroundColor: backgroundColor)); - - _defaultConfig = BrnThemeConfigurator.instance - .getConfig(configId: _defaultConfig.configId) - .appBarConfig - .merge(_defaultConfig); + _defaultConfig = globalAppBarConfig.merge(themeData).merge(_appBarConfig); Widget? flexibleSpace; if (this.flexibleSpace != null) { @@ -624,8 +639,7 @@ class _BrnSearchResultAppBar extends StatelessWidget { _defaultConfig = _defaultConfig.merge(BrnAppBarConfig.dark()); } - _defaultConfig = _defaultConfig - .merge(BrnAppBarConfig( + _defaultConfig = _defaultConfig.merge(BrnAppBarConfig( backgroundColor: this.backgroundColor, showDefaultBottom: this.showDefaultBottom, )); diff --git a/lib/src/theme/configs/brn_appbar_config.dart b/lib/src/theme/configs/brn_appbar_config.dart index e5d2ee05..455bf104 100644 --- a/lib/src/theme/configs/brn_appbar_config.dart +++ b/lib/src/theme/configs/brn_appbar_config.dart @@ -51,6 +51,10 @@ class BrnAppBarConfig extends BrnBaseConfig { EdgeInsets? titlePadding, double? iconSize, String configId = GLOBAL_CONFIG_ID, + BrnTextStyle? titleStyle, + BrnTextStyle? actionsStyle, + Color? backgroundColor, + Widget Function()? leadIconBuilder, }) : _appBarHeight = appBarHeight, _titleMaxLength = titleMaxLength, _leftAndRightPadding = leftAndRightPadding, @@ -58,24 +62,25 @@ class BrnAppBarConfig extends BrnBaseConfig { _titlePadding = titlePadding, _iconSize = iconSize, super(configId: configId) { - _backgroundColor = Color(0xff2E313B); - _leadIconBuilder = () => Image.asset( - BrnAsset.iconBackWhite, - package: BrnStrings.flutterPackageName, - width: BrnAppBarTheme.iconSize, - height: BrnAppBarTheme.iconSize, - fit: BoxFit.fitHeight, - ); + _backgroundColor = backgroundColor ?? Color(0xff2E313B); + _leadIconBuilder = leadIconBuilder ?? + () => Image.asset( + BrnAsset.iconBackWhite, + package: BrnStrings.flutterPackageName, + width: BrnAppBarTheme.iconSize, + height: BrnAppBarTheme.iconSize, + fit: BoxFit.fitHeight, + ); _titleStyle = BrnTextStyle( fontSize: BrnAppBarTheme.titleFontSize, fontWeight: FontWeight.w600, color: BrnAppBarTheme.darkTextColor, - ); + ).merge(titleStyle); _actionsStyle = BrnTextStyle( color: BrnAppBarTheme.darkTextColor, fontSize: BrnAppBarTheme.actionFontSize, fontWeight: FontWeight.w600, - ); + ).merge(actionsStyle); _systemUiOverlayStyle = SystemUiOverlayStyle.light; } @@ -86,6 +91,10 @@ class BrnAppBarConfig extends BrnBaseConfig { double? itemSpacing, EdgeInsets? titlePadding, double? iconSize, + BrnTextStyle? titleStyle, + BrnTextStyle? actionsStyle, + Color? backgroundColor, + Widget Function()? leadIconBuilder, String configId = GLOBAL_CONFIG_ID, }) : _appBarHeight = appBarHeight, _titleMaxLength = titleMaxLength, @@ -94,24 +103,25 @@ class BrnAppBarConfig extends BrnBaseConfig { _titlePadding = titlePadding, _iconSize = iconSize, super(configId: configId) { - _backgroundColor = Colors.white; - _leadIconBuilder = () => Image.asset( - BrnAsset.iconBackBlack, - package: BrnStrings.flutterPackageName, - width: BrnAppBarTheme.iconSize, - height: BrnAppBarTheme.iconSize, - fit: BoxFit.fitHeight, - ); + _backgroundColor = backgroundColor ?? Colors.white; + _leadIconBuilder = leadIconBuilder ?? + () => Image.asset( + BrnAsset.iconBackBlack, + package: BrnStrings.flutterPackageName, + width: BrnAppBarTheme.iconSize, + height: BrnAppBarTheme.iconSize, + fit: BoxFit.fitHeight, + ); _titleStyle = BrnTextStyle( fontSize: BrnAppBarTheme.titleFontSize, fontWeight: FontWeight.w600, color: BrnAppBarTheme.lightTextColor, - ); + ).merge(titleStyle); _actionsStyle = BrnTextStyle( color: BrnAppBarTheme.lightTextColor, fontSize: BrnAppBarTheme.actionFontSize, fontWeight: FontWeight.w600, - ); + ).merge(actionsStyle); _systemUiOverlayStyle = SystemUiOverlayStyle.dark; } @@ -204,7 +214,7 @@ class BrnAppBarConfig extends BrnBaseConfig { bool get showDefaultBottom => _showDefaultBottom ?? - BrnDefaultConfigUtils.defaultAppBarConfig.showDefaultBottom; + BrnDefaultConfigUtils.defaultAppBarConfig.showDefaultBottom; @override void initThemeConfig(