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

Card Components Null safe adapter #53

Merged
merged 4 commits into from
Jan 12, 2022
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,6 @@ build/
!**/ios/**/default.perspectivev3
!/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages
pubspec.lock

Copy link
Collaborator

Choose a reason for hiding this comment

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

可不提 😃

Copy link
Contributor Author

Choose a reason for hiding this comment

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

.fvm 这个吗? 如果是,我建议可以添加哈。毕竟大家的 Flutter 版本都不同,利用 FVM 管控很正常哈。😜

# FVM
.fvm
20 changes: 12 additions & 8 deletions lib/src/components/card/bubble_card/brn_bubble_text.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// @dart=2.9


import 'package:bruno/src/components/text/brn_expandable_text.dart';
import 'package:bruno/src/theme/brn_theme_configurator.dart';
Expand Down Expand Up @@ -34,16 +34,20 @@ class BrnBubbleText extends StatelessWidget {
final String text;

///最多显示的行数
final int maxLines;
final int? maxLines;

///展开收起回调
final TextExpandedCallback onExpanded;
final TextExpandedCallback? onExpanded;

///气泡的圆角 默认是4
final double radius;

const BrnBubbleText(
{Key key, this.text, this.maxLines, this.onExpanded, this.radius = 4})
{Key? key,
this.text = '',
this.maxLines,
this.onExpanded,
this.radius = 4})
: super(key: key);

@override
Expand Down Expand Up @@ -72,12 +76,12 @@ class BrnBubbleText extends StatelessWidget {
shape: BoxShape.rectangle,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(0),
topRight: Radius.circular(radius ?? 4),
bottomLeft: Radius.circular(radius ?? 4),
bottomRight: Radius.circular(radius ?? 4))),
topRight: Radius.circular(radius),
KennethYo marked this conversation as resolved.
Show resolved Hide resolved
bottomLeft: Radius.circular(radius),
bottomRight: Radius.circular(radius))),
padding: EdgeInsets.only(left: 20, right: 20, top: 12, bottom: 12),
child: BrnExpandableText(
text: text ?? "",
text: text,
maxLines: maxLines,
color: Color(0xFFF8F8F8),
onExpanded: onExpanded,
Expand Down
4 changes: 2 additions & 2 deletions lib/src/components/card/bubble_card/brn_insert_info.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// @dart=2.9


import 'package:bruno/src/theme/brn_theme_configurator.dart';
import 'package:bruno/src/utils/brn_tools.dart';
Expand Down Expand Up @@ -28,7 +28,7 @@ class BrnInsertInfo extends StatelessWidget {
final String infoText;
final int maxLines;

const BrnInsertInfo({Key key, @required this.infoText, this.maxLines = 2})
const BrnInsertInfo({Key? key, required this.infoText, this.maxLines = 2})
: super(key: key);

@override
Expand Down
64 changes: 32 additions & 32 deletions lib/src/components/card/content_card/brn_enhance_number_card.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// @dart=2.9


import 'package:bruno/src/constants/brn_asset_constants.dart';
import 'package:bruno/src/constants/brn_strings_constants.dart';
Expand Down Expand Up @@ -57,13 +57,13 @@ import 'package:flutter/widgets.dart';
///
///
class BrnEnhanceNumberCard extends StatelessWidget {
final List<BrnNumberInfoItemModel> itemChildren;
final List<BrnNumberInfoItemModel>? itemChildren;

///如果超过一行,行间距则 默认为16
final double runningSpace;
final double? runningSpace;

///Item的上半部分和下半部分的间距 默认为8
final double itemRunningSpace;
final double? itemRunningSpace;

///每一行显示的数量 默认为3
final int rowCount;
Expand All @@ -76,10 +76,10 @@ class BrnEnhanceNumberCard extends StatelessWidget {

final TextAlign itemTextAlign;

final BrnEnhanceNumberCardConfig themeData;
final BrnEnhanceNumberCardConfig? themeData;

BrnEnhanceNumberCard({
Key key,
Key? key,
this.itemChildren,
this.rowCount = 3,
this.runningSpace,
Expand All @@ -102,7 +102,7 @@ class BrnEnhanceNumberCard extends StatelessWidget {
.enhanceNumberCardConfig
.merge(defaultConfig);

if (itemChildren == null || itemChildren.length == 0) {
if (itemChildren == null || itemChildren!.length == 0) {
return Container(
height: 0,
width: 0,
Expand All @@ -116,25 +116,25 @@ class BrnEnhanceNumberCard extends StatelessWidget {
);
// 容错显示的行数 显示三行
int count = rowCount;
if (rowCount <= 0 || rowCount > itemChildren.length) {
if (rowCount <= 0 || rowCount > itemChildren!.length) {
count = 3;
}
double width = constraints.maxWidth;
double singleWidth = (width - padding.left - padding.right) / count;

if (itemChildren.length > 1) {
if (itemChildren!.length > 1) {
// 平铺下来
contentWidget = Wrap(
runSpacing: defaultConfig.runningSpace,
spacing: 0.0,
children: itemChildren.map((data) {
children: itemChildren!.map((data) {
//每行的最后一个 不显示分割线
//最后一个元素 不显示分割线
bool condition1 = (itemChildren.indexOf(data) + 1) % count == 0;
bool condition2 = itemChildren.last == data;
bool condition1 = (itemChildren!.indexOf(data) + 1) % count == 0;
bool condition2 = itemChildren!.last == data;
bool allCondition = condition1 || condition2;

bool isFirst = (itemChildren.indexOf(data) + 1) % count == 1;
bool isFirst = (itemChildren!.indexOf(data) + 1) % count == 1;
return Container(
width: singleWidth,
child: Row(
Expand Down Expand Up @@ -165,7 +165,7 @@ class BrnEnhanceNumberCard extends StatelessWidget {
}).toList(),
);
} else {
contentWidget = _buildItemWidget(itemChildren[0], defaultConfig);
contentWidget = _buildItemWidget(itemChildren![0], defaultConfig);
}

return Container(
Expand All @@ -179,7 +179,7 @@ class BrnEnhanceNumberCard extends StatelessWidget {

Widget _buildItemWidget(
BrnNumberInfoItemModel model, BrnEnhanceNumberCardConfig config,
{double width}) {
{double? width}) {
return Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
Expand All @@ -196,9 +196,9 @@ class BrnEnhanceNumberCard extends StatelessWidget {

Widget _buildTopWidget(
BrnNumberInfoItemModel model, BrnEnhanceNumberCardConfig config,
{double width}) {
{double? width}) {
if (model.topWidget != null) {
return model.topWidget;
return model.topWidget!;
}
return Row(
mainAxisSize: MainAxisSize.min,
Expand All @@ -209,7 +209,7 @@ class BrnEnhanceNumberCard extends StatelessWidget {
Container(
height: 26,
transform: Matrix4.translationValues(0, 1, 0),
child: Text(model.number,
child: Text(model.number!,
style: TextStyle(
textBaseline: TextBaseline.ideographic,
color: config.titleTextStyle.color,
Expand All @@ -226,9 +226,9 @@ class BrnEnhanceNumberCard extends StatelessWidget {

Widget _buildBottomWidget(
BrnNumberInfoItemModel model, BrnEnhanceNumberCardConfig config,
{double width}) {
{double? width}) {
if (model.bottomWidget != null) {
return model.bottomWidget;
return model.bottomWidget!;
}
TextSpan span = TextSpan(
text: model.title ?? "",
Expand Down Expand Up @@ -269,7 +269,7 @@ class BrnEnhanceNumberCard extends StatelessWidget {
),
GestureDetector(
onTap: () {
model.iconTapCallBack(model);
model.iconTapCallBack!(model);
},
child: icon,
)
Expand All @@ -279,7 +279,7 @@ class BrnEnhanceNumberCard extends StatelessWidget {
return text;
}

Widget _getPreWidget(String preDesc, BrnEnhanceNumberCardConfig config) {
Widget _getPreWidget(String? preDesc, BrnEnhanceNumberCardConfig config) {
if (preDesc == null || preDesc.isEmpty) {
return Container(
height: 0,
Expand All @@ -289,7 +289,7 @@ class BrnEnhanceNumberCard extends StatelessWidget {
return Padding(
padding: const EdgeInsets.only(left: 1),
child: Text(
preDesc ?? "",
preDesc,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(
Expand All @@ -301,7 +301,7 @@ class BrnEnhanceNumberCard extends StatelessWidget {
);
}

Widget _getLastWidget(String lastDesc, BrnEnhanceNumberCardConfig config) {
Widget _getLastWidget(String? lastDesc, BrnEnhanceNumberCardConfig config) {
if (lastDesc == null || lastDesc.isEmpty) {
return Container(
height: 0,
Expand All @@ -310,7 +310,7 @@ class BrnEnhanceNumberCard extends StatelessWidget {
}
return Padding(
padding: const EdgeInsets.only(left: 1, top: 0),
child: Text(lastDesc ?? "",
child: Text(lastDesc,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(
Expand All @@ -324,28 +324,28 @@ class BrnEnhanceNumberCard extends StatelessWidget {
/// 用来显示强化数据的model
class BrnNumberInfoItemModel {
///number必须是非中文,否则会展示异常,如果有中文信息 则设置pre和last字段
final String number;
final String? number;

///下半部分的辅助信息
final String title;
final String? title;

///强化信息的前面展示字段
final String preDesc;
final String? preDesc;

///强化信息的后面展示字段
final String lastDesc;
final String? lastDesc;

///icon的事件
final Function(BrnNumberInfoItemModel) iconTapCallBack;
final Function(BrnNumberInfoItemModel)? iconTapCallBack;

///icon的样式 可枚举 , 默认为问号
final BrnNumberInfoIcon numberInfoIcon;

///上半部分的自定义内容 如果设置了优先级则高于 number、preDesc和lastDesc
final Widget topWidget;
final Widget? topWidget;

///下半部分的自定义内容 如果设置了优先级则高于 title
final Widget bottomWidget;
final Widget? bottomWidget;

///上部分的:(number、preDesc、lastDesc)和topWidget 必须设置一个
///下部分的:title和title 必须设置一个
Expand Down
Loading