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

migrate form to null safety #86

Merged
merged 32 commits into from
Jan 24, 2022
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
d2a37e0
Theme: 优化单例实现,初步优化 BrnAllThemeConfig 属性获取不为 null
zhoujuanjuan Dec 27, 2021
75a2be3
refactor:优化theme,暴露非null引用
zhoujuanjuan Dec 27, 2021
f97bf07
theme:去除无用信息及优化部分代码
zhoujuanjuan Dec 28, 2021
44ba17a
theme:增加属性类型
zhoujuanjuan Dec 28, 2021
cad7451
Merge branch 'LianjiaTech:null-safe' into null-safe
zhoujuanjuan Dec 31, 2021
c19203f
优化修复 EventBus
zhoujuanjuan Dec 31, 2021
c96cdd3
Merge branch 'LianjiaTech:null-safe' into null-safe
zhoujuanjuan Jan 4, 2022
2c99d35
Merge branch 'LianjiaTech:null-safe' into null-safe
zhoujuanjuan Jan 4, 2022
c7ae392
Merge branch 'LianjiaTech:null-safe' into null-safe
zhoujuanjuan Jan 5, 2022
6e0834b
迁移example ,优化常量命名,增加export
zhoujuanjuan Jan 4, 2022
5db665d
migrate brn_empty_status.dart
zhoujuanjuan Jan 5, 2022
7c12fc8
删除 BrnThemeImg
zhoujuanjuan Jan 6, 2022
0b75394
Merge remote-tracking branch 'upstream/null-safe' into null-safe
zhoujuanjuan Jan 6, 2022
c00cfd5
fix:tagConfig merge方法增加判空处理
zhoujuanjuan Jan 6, 2022
ada5216
fix:revert tagConfig
zhoujuanjuan Jan 7, 2022
beec378
fix:BrnAbnormalStateWidget空处理
zhoujuanjuan Jan 7, 2022
b852eb6
Merge branch 'LianjiaTech:null-safe' into null-safe
zhoujuanjuan Jan 7, 2022
e69a944
Merge branch 'LianjiaTech:null-safe' into null-safe
zhoujuanjuan Jan 10, 2022
e31532f
Merge branch 'LianjiaTech:null-safe' into null-safe
zhoujuanjuan Jan 11, 2022
162fcfe
Migrated tabbar to null-safety
zhoujuanjuan Jan 11, 2022
2bd473f
Merge branch 'LianjiaTech:null-safe' into null-safe
zhoujuanjuan Jan 12, 2022
103ab13
Migrated scroll_anchor to null-safety
zhoujuanjuan Jan 11, 2022
2b141fd
Merge branch 'LianjiaTech:null-safe' into null-safe
zhoujuanjuan Jan 13, 2022
04b7a3e
Merge branch 'LianjiaTech:null-safe' into null-safe
zhoujuanjuan Jan 17, 2022
5748da7
fix:修复迁移tabar问题
zhoujuanjuan Jan 17, 2022
8c25d72
Merge branch 'LianjiaTech:null-safe' into null-safe
zhoujuanjuan Jan 18, 2022
1c33fd9
migrate form to null safety
zhoujuanjuan Jan 18, 2022
07c308a
fix:修复tabbar报错及selection警告信息
zhoujuanjuan Jan 18, 2022
fdf45af
Merge branch 'LianjiaTech:null-safe' into null-safe
zhoujuanjuan Jan 19, 2022
e1749fe
Merge remote-tracking branch 'upstream/null-safe' into null-safe
zhoujuanjuan Jan 24, 2022
0b4c168
fix:修复迁移问题
zhoujuanjuan Jan 24, 2022
3f3b4d3
fix:优化迁移部分问题key和style非空问题
zhoujuanjuan Jan 24, 2022
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 @@ -63,7 +63,6 @@ class StepInputExamplePage extends StatelessWidget {
title: "自然到访保护期",
subTitle: "这里是副标题",
tipLabel: "标签",
value: 0,
maxLimit: 5,
minLimit: 1,
onTip: () {
Expand Down Expand Up @@ -96,7 +95,6 @@ class StepInputExamplePage extends StatelessWidget {
title: "自然到访保护期",
subTitle: "这里是副标题",
tipLabel: "标签",
value: 0,
maxLimit: 5,
minLimit: 1,
onTip: () {
Expand Down
1 change: 0 additions & 1 deletion lib/bruno.dart
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ export 'src/components/loading/brn_loading.dart';

//导航栏
export 'src/components/navbar/brn_appbar.dart';
export 'src/components/navbar/brn_empty_appbar.dart';

//搜索bar
export 'src/components/navbar/brn_search_bar.dart';
Expand Down
2 changes: 1 addition & 1 deletion lib/src/components/form/base/brn_form_item_type.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// @dart=2.9


class BrnPrefixIconType {
static const String TYPE_NORMAL = "type_normal";
Expand Down
6 changes: 3 additions & 3 deletions lib/src/components/form/base/input_item_interface.dart
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
/// 用于model兼容回调
/// 主要用于各种点击事件

// @dart=2.9


typedef OnBrnFormSelectAll = void Function(int index, bool isSelect);

/// 主要用于各种输入值变化
typedef OnBrnFormRadioValueChanged = void Function(
String oldStr, String newStr);
String? oldStr, String? newStr);
typedef OnBrnFormSwitchChanged = void Function(bool oldValue, bool newValue);
typedef OnBrnFormValueChanged = void Function(int oldValue, int newValue);
typedef OnBrnFormMultiChoiceValueChanged = void Function(
List<String> oldValue, List<String> newValue);
List<String> oldValue, List<String>? newValue);
typedef OnBrnFormBtnSelectChanged = void Function(
List<bool> oldValue, List<bool> newValue);

Expand Down
109 changes: 44 additions & 65 deletions lib/src/components/form/items/general/brn_multi_choice_input_item.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
// @dart=2.9

import 'package:bruno/bruno.dart';
import 'package:bruno/src/components/form/base/brn_form_item_type.dart';
import 'package:bruno/src/components/form/base/input_item_interface.dart';
import 'package:bruno/src/components/form/utils/brn_form_util.dart';
import 'package:bruno/src/components/radio/brn_radio_core.dart';
import 'package:bruno/src/theme/brn_theme_configurator.dart';
import 'package:bruno/src/theme/configs/brn_form_config.dart';
import 'package:flutter/material.dart';
Expand All @@ -19,23 +16,23 @@ import 'package:flutter/widgets.dart';
// ignore: must_be_immutable
class BrnMultiChoiceInputFormItem extends StatefulWidget {
/// 录入项的唯一标识,主要用于录入类型页面框架中
final String label;
final String? label;

/// 录入项类型,主要用于录入类型页面框架中
String type = BrnInputItemType.MULTI_CHOICE_INPUT_TYPE;
final String type = BrnInputItemType.MULTI_CHOICE_INPUT_TYPE;

/// 录入项标题
final String title;

/// 录入项子标题
final String subTitle;
final String? subTitle;

/// 录入项提示(问号图标&文案) 用户点击时触发onTip回调。
/// 1. 若赋值为 空字符串("")时仅展示"问号"图标,
/// 2. 若赋值为非空字符串时 展示"问号图标&文案",
/// 3. 若不赋值或赋值为null时 不显示提示项
/// 默认值为 3
final String tipLabel;
final String? tipLabel;

/// 录入项前缀图标样式 "添加项" "删除项" 详见 PrefixIconType类
final String prefixIconType;
Expand All @@ -50,51 +47,51 @@ class BrnMultiChoiceInputFormItem extends StatefulWidget {
final bool isEdit;

/// 点击"+"图标回调
final VoidCallback onAddTap;
final VoidCallback? onAddTap;

/// 点击"-"图标回调
final VoidCallback onRemoveTap;
final VoidCallback? onRemoveTap;

/// 点击"?"图标回调
final VoidCallback onTip;
final VoidCallback? onTip;

/// 特殊字段
List<String> value;
final List<String> value;

/// 内容
List<String> options;
final List<String> options;

/// 局部禁用list
List<bool> enableList;
final List<bool> enableList;

/// 选项选中状态变化回调
final OnBrnFormMultiChoiceValueChanged onChanged;
final OnBrnFormMultiChoiceValueChanged? onChanged;

/// form配置
BrnFormItemConfig themeData;
BrnFormItemConfig? themeData;

BrnMultiChoiceInputFormItem(
{Key key,
{Key? key,
this.label,
this.title: "",
this.title = "",
this.subTitle,
this.tipLabel,
this.prefixIconType: BrnPrefixIconType.TYPE_NORMAL,
this.error: "",
this.isEdit: true,
this.isRequire: true,
this.prefixIconType = BrnPrefixIconType.TYPE_NORMAL,
this.error = "",
this.isEdit = true,
this.isRequire = true,
this.onAddTap,
this.onRemoveTap,
this.onTip,
this.value,
this.options,
this.enableList,
this.value = const <String>[],
this.options = const <String>[],
this.enableList = const <bool>[],
this.onChanged,
this.themeData})
: super() {
this.themeData ??= BrnFormItemConfig();
this.themeData = BrnThemeConfigurator.instance
.getConfig(configId: this.themeData.configId)
.getConfig(configId: this.themeData!.configId)
.formItemConfig
.merge(this.themeData);
}
Expand All @@ -108,11 +105,10 @@ class BrnMultiChoiceInputFormItem extends StatefulWidget {
class BrnMultiChoiceInputFormItemState
extends State<BrnMultiChoiceInputFormItem> {
// 标记选项的选中状态,内部变量无须初始化。初始化选中状态通过设置value字段设置
List<bool> _selectStatus;
List<bool?>? _selectStatus;

@override
void initState() {
_initSpecialParams();
_initSelectedStatus();
super.initState();
}
Expand Down Expand Up @@ -170,8 +166,8 @@ class BrnMultiChoiceInputFormItemState
);
}

List<Widget> getCheckboxList(List<String> options) {
List<Widget> result = List();
List<Widget> getCheckboxList(List<String>? options) {
List<Widget> result = [];
if (options == null || options.isEmpty) {
result.add(Container());
return result;
Expand All @@ -196,18 +192,18 @@ class BrnMultiChoiceInputFormItemState
radioIndex: index,
disable: getRadioEnableState(index),
isSelected:
(_selectStatus != null && pos < _selectStatus.length)
? _selectStatus[pos]
(_selectStatus != null && pos < _selectStatus!.length)
? _selectStatus![pos]!
: false,
onValueChangedAtIndex: (position, value) {
_selectStatus[position] = value;
List<String> oldValue = List<String>()..addAll(widget.value);
_selectStatus![position] = value;
List<String> oldValue = <String>[]..addAll(widget.value);

setState(() {
widget.value.clear();

for (int i = 0; i < _selectStatus.length; ++i) {
if (_selectStatus[i]) {
for (int i = 0; i < _selectStatus!.length; ++i) {
if (_selectStatus![i]!) {
widget.value.add(widget.options[i]);
}
}
Expand All @@ -226,22 +222,21 @@ class BrnMultiChoiceInputFormItemState
return result;
}

TextStyle getOptionTextStyle(int index) {
TextStyle result = BrnFormUtil.getOptionTextStyle(widget.themeData);
if (index < 0 || index >= _selectStatus.length) {
TextStyle? getOptionTextStyle(int index) {
TextStyle? result = BrnFormUtil.getOptionTextStyle(widget.themeData);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

themeData 不为空的话,result 可以为非空类型

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1

if (index < 0 || index >= _selectStatus!.length) {
return result;
}

if (_selectStatus[index]) {
if (_selectStatus![index]!) {
result = BrnFormUtil.getOptionSelectedTextStyle(widget.themeData);
}

if (!widget.isEdit) {
result = BrnFormUtil.getIsEditTextStyle(widget.themeData, widget.isEdit);
}

if (widget.enableList != null &&
widget.enableList.isNotEmpty &&
if (widget.enableList.isNotEmpty &&
widget.enableList.length > index &&
!widget.enableList[index]) {
result = BrnFormUtil.getIsEditTextStyle(widget.themeData, false);
Expand All @@ -255,41 +250,25 @@ class BrnMultiChoiceInputFormItemState
return true;
}

if (widget.enableList == null ||
widget.enableList.isEmpty ||
widget.enableList.length < index) {
if (widget.enableList.isEmpty || widget.enableList.length < index) {
return false;
}

return !widget.enableList[index];
}

void _initSpecialParams() {
if (widget.value == null) {
widget.value = List<String>();
}

if (widget.options == null) {
widget.options = List<String>();
}

if (widget.enableList == null) {
widget.enableList = List<bool>();
}
}

void _initSelectedStatus() {
if (widget.options != null && widget.options.isNotEmpty) {
_selectStatus = List<bool>(widget.options.length);
if (widget.options.isNotEmpty) {
_selectStatus = List.filled(widget.options.length, false);
} else {
_selectStatus = List<bool>();
_selectStatus = <bool>[];
}

for (int index = 0; index < _selectStatus.length; ++index) {
_selectStatus[index] = false;
for (int index = 0; index < _selectStatus!.length; ++index) {
_selectStatus![index] = false;
}

if (widget.value == null || widget.value.isEmpty) {
if (widget.value.isEmpty) {
return;
}

Expand All @@ -299,7 +278,7 @@ class BrnMultiChoiceInputFormItemState
if (pos < 0) {
return;
}
_selectStatus[pos] = true;
_selectStatus![pos] = true;
}
}
}
Loading