Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

♻️ [NNBD] Part 1. Migrate configs #28

Merged
merged 4 commits into from
Dec 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -297,18 +297,18 @@ class _BrnActionSheetSelectedItemListState<T>
widget._alphaAnimationController = alphaAnimationController;
Animation yAnimation = Tween(begin: 65.0, end: this.getContentHeight())
.animate(yAnimationController)
..addListener(() {
setState(() => {});
})
..addStatusListener((status) {
if (status == AnimationStatus.dismissed) {
widget.onDismiss(_isClosedByClear);
}
});
..addListener(() {
setState(() => {});
})
..addStatusListener((status) {
if (status == AnimationStatus.dismissed) {
widget.onDismiss(_isClosedByClear);
}
});
widget._yAnimation = yAnimation;
Animation alphaAnimation = Tween(begin: 0.0, end: 0.7)
.animate(alphaAnimationController)
..addListener(() {});
..addListener(() {});
widget._alphaAnimation = alphaAnimation;
yAnimationController.forward();
alphaAnimationController.forward();
Expand Down
6 changes: 3 additions & 3 deletions lib/src/components/empty/brn_empty_status.dart
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ class BrnAbnormalStateWidget extends StatelessWidget {
BorderRadius.all(Radius.circular(themeData?.btnRadius))),
child: Text(operateTexts[0] ?? "",
textAlign: TextAlign.center,
style: themeData?.singleBrnTextStyle?.generateTextStyle()),
style: themeData?.singleTextStyle?.generateTextStyle()),
),
);
} else if (OperateAreaType.DoubleButton == operateAreaType) {
Expand All @@ -242,7 +242,7 @@ class BrnAbnormalStateWidget extends StatelessWidget {
BorderRadius.all(Radius.circular(themeData?.btnRadius))),
child: Text(operateTexts[0] ?? "",
textAlign: TextAlign.center,
style: themeData?.doubleBrnTextStyle?.generateTextStyle()),
style: themeData?.doubleTextStyle?.generateTextStyle()),
),
),
Container(
Expand All @@ -260,7 +260,7 @@ class BrnAbnormalStateWidget extends StatelessWidget {
BorderRadius.all(Radius.circular(themeData?.btnRadius))),
child: Text(operateTexts[1] ?? "",
textAlign: TextAlign.center,
style: themeData?.doubleBrnTextStyle?.generateTextStyle()),
style: themeData?.doubleTextStyle?.generateTextStyle()),
),
),
],
Expand Down
2 changes: 2 additions & 0 deletions lib/src/components/navbar/brn_appbar_theme.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import 'package:flutter/material.dart';

class BrnAppBarTheme {
const BrnAppBarTheme._();

/// [BrnAppBar] 高度固定值
static const double appBarHeight = 44;

Expand Down
12 changes: 8 additions & 4 deletions lib/src/components/picker/base/brn_picker_constants.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import 'package:flutter/material.dart';

/// Default value of DatePicker's item [TextStyle].
const TextStyle DATETIME_PICKER_ITEM_TEXT_STYLE =
const TextStyle(color: Color(0xFF222222), fontSize: 18.0);
const TextStyle DATETIME_PICKER_ITEM_TEXT_STYLE = TextStyle(
color: Color(0xFF222222),
fontSize: 18.0,
);

/// Default value of DatePicker's background color.
const PICKER_BACKGROUND_COLOR = Colors.white;
Expand All @@ -20,5 +22,7 @@ const double PICKER_TITLE_HEIGHT = 48.0;
const double PICKER_ITEM_HEIGHT = 48.0;

/// Default value of DatePicker's item [TextStyle].
const TextStyle PICKER_ITEM_TEXT_STYLE =
const TextStyle(color: Color(0xFF222222), fontSize: 18.0);
const TextStyle PICKER_ITEM_TEXT_STYLE = TextStyle(
color: Color(0xFF222222),
fontSize: 18.0,
);
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class _BrnLayerMoreSelectionPageState extends State<BrnLayerMoreSelectionPage>
_controller.forward();

currentIndex = 0;
firstList = List();
firstList = [];
_originalSelectedItemsList = widget.entityData.selectedList();

_initData();
Expand Down Expand Up @@ -303,12 +303,12 @@ class _BrnLayerMoreSelectionPageState extends State<BrnLayerMoreSelectionPage>
Widget _buildLeftItem(int index) {
//如果房山 被选中了或者房山处于正在选择的状态 则加粗
TextStyle textStyle =
widget.themeData.flayNormalTextStyle.generateTextStyle();
widget.themeData.flayerNormalTextStyle.generateTextStyle();
if (index == currentIndex) {
textStyle = widget.themeData.flatSelectedTextStyle.generateTextStyle();
textStyle = widget.themeData.flayerSelectedTextStyle.generateTextStyle();
} else if ((firstList[index].isSelected) &&
firstList[index].selectedList().isNotEmpty) {
textStyle = widget.themeData.flatBoldTextStyle.generateTextStyle();
textStyle = widget.themeData.flayerBoldTextStyle.generateTextStyle();
}

List<BrnSelectionEntity> list = firstList[index].selectedList();
Expand Down Expand Up @@ -404,7 +404,7 @@ class _BrnLayerMoreSelectionPageState extends State<BrnLayerMoreSelectionPage>

void _initData() {
//填充一级筛选数据
firstList = widget.entityData.children ?? List();
firstList = widget.entityData.children ?? [];
//找到一级需要显示 的索引
for (int i = 0; i < firstList.length; i++) {
if (firstList[i].selectedList().isNotEmpty) {
Expand Down Expand Up @@ -433,15 +433,15 @@ class _BrnLayerMoreSelectionPageState extends State<BrnLayerMoreSelectionPage>
child: Text(
tmp.title.toString(),
style: tmp.isSelected
? widget.themeData.flatSelectedTextStyle.generateTextStyle()
: widget.themeData.flayNormalTextStyle.generateTextStyle(),
? widget.themeData.flayerSelectedTextStyle.generateTextStyle()
: widget.themeData.flayerNormalTextStyle.generateTextStyle(),
),
),
Container(
height: 16,
width: 16,
child: tmp.isSelected
? BrnThemeImg.instance.CHECKED_STATUS
? BrnThemeImg.instance.checkedStatus
: BrunoTools.getAssetImage(BrnAsset.iconUnSelect),
)
],
Expand All @@ -452,8 +452,8 @@ class _BrnLayerMoreSelectionPageState extends State<BrnLayerMoreSelectionPage>
return Text(tmp.title.toString(),
textAlign: TextAlign.left,
style: tmp.isSelected
? widget.themeData.flatSelectedTextStyle.generateTextStyle()
: widget.themeData.flayNormalTextStyle.generateTextStyle());
? widget.themeData.flayerSelectedTextStyle.generateTextStyle()
: widget.themeData.flayerNormalTextStyle.generateTextStyle());
}

//初始化二级的选中(小白楼)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ class _BrnSelectionAnimationWidgetState
begin: 0.0,
end: widget.controller.screenHeight - widget.controller.listViewTop)
.animate(_controller)
..addListener(() {
//这行如果不写,没有动画效果
setState(() {});
});
..addListener(() {
//这行如果不写,没有动画效果
setState(() {});
});

if (_isControllerDisposed) return;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ class _BrnSelectionDatePickerAnimationWidgetState

_animation = Tween(begin: widget.controller.screenHeight, end: 300.0)
.animate(_controller)
..addListener(() {
//这行如果不写,没有动画效果
setState(() {});
});
..addListener(() {
//这行如果不写,没有动画效果
setState(() {});
});

if (_isControllerDisposed) return;

Expand Down
2 changes: 2 additions & 0 deletions lib/src/constants/brn_asset_constants.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
class BrnAsset {
const BrnAsset._();

static const String emptyState = "images/empty_state.png";
static const String stepTitle = 'images/img_step_title.png';

Expand Down
4 changes: 3 additions & 1 deletion lib/src/constants/brn_strings_constants.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
class BrnStrings {
//加载获取assets资源需要
const BrnStrings._();

/// 加载获取 assets 资源需要
static const String flutterPackageName = "bruno";

static const String getDateFailed = "获取数据失败,请重试";
Expand Down
53 changes: 32 additions & 21 deletions lib/src/theme/base/brn_base_config.dart
Original file line number Diff line number Diff line change
@@ -1,43 +1,54 @@
// @dart=2.9

import 'package:bruno/src/theme/brn_theme_configurator.dart';
import 'package:bruno/src/theme/base/brn_default_config_utils.dart';
import 'package:bruno/src/theme/configs/brn_common_config.dart';

/// 组件配置基类
abstract class BrnBaseConfig {
String configId;

BrnCommonConfig _currentLevelCommonConfig;

BrnBaseConfig(
{this.configId = BrnThemeConfigurator.GLOBAL_CONFIG_ID,
bool autoFlatConfig = false}) {
BrnBaseConfig({
String configId = GLOBAL_CONFIG_ID,
bool autoFlatConfig = false,
}) : _configId = configId {
if (autoFlatConfig) {
initThemeConfig(configId);
}
}

String get configId => _configId;
String _configId;
BrnCommonConfig? _currentLevelCommonConfig;

/// 部分代码示意如下:
/// cardTitleConfig.detailTextStyle.merge(BrnTextStyle(
/// color: commonConfig.colorTextBase,
/// fontSize: commonConfig.fontSizeBase,
/// ).merge(detailTextStyle));
/// 第一步 以commonConfig字段为基础merge detailTextStyle detailTextStyle 字段优先级高
/// 当detailTextStyle中字段(如:color)为null时会使用commonConfig.colorTextBase
/// 第二步 以默认上一级配置为基础merge 第一步结果,当第一步中字段(如:color)为空时 ,
/// 使用上一层级配置的color(cardTitleConfig.detailTextStyle.color)
void initThemeConfig(String configId,
{BrnCommonConfig currentLevelCommonConfig}) {
///
/// ```dart
/// cardTitleConfig.detailTextStyle.merge(
/// BrnTextStyle(
/// color: commonConfig.colorTextBase,
/// fontSize: commonConfig.fontSizeBase,
/// ).merge(detailTextStyle),
/// );
///
/// - 以 `commonConfig` 字段为基础 merge `detailTextStyle`。
/// `detailTextStyle` 字段优先级高,当detailTextStyle中字段(如 color)为 null 时
/// 会使用 `commonConfig.colorTextBase`。
/// - 以默认上一级配置为基础 merge 第一步的结果,当第一步中字段(如 color)为空时,
/// 使用上一层级配置的 color (`cardTitleConfig.detailTextStyle.color`)。
void initThemeConfig(
String configId, {
BrnCommonConfig? currentLevelCommonConfig,
}) {
_currentLevelCommonConfig = currentLevelCommonConfig;
}

/// 当自定义组件的配置时调用
/// 根据自定义时传入的configId对配置字段打平
/// 根据自定义时传入的 [configId] 对配置字段打平
void initThemeConfigPersonal() {
initThemeConfig(configId);
}

BrnCommonConfig get commonConfig =>
_currentLevelCommonConfig ??
BrnThemeConfigurator.instance.getConfig(configId: configId).commonConfig;
BrnThemeConfigurator.instance
.getConfig(configId: configId)
.commonConfig ??
BrnDefaultConfigUtils.defaultCommonConfig;
}
Loading