Skip to content

Commit

Permalink
Migrate BrnStateTag、BrnTagCustom、BrnSelectTag、BrnDeleteTag to null-sa…
Browse files Browse the repository at this point in the history
…fe (#46)

* [null-safe]: BrnStateTag、BrnTagCustom、BrnSelectTag、BrnDeleteTag 空安全适配

* perf: BrnDeleteTag null-safe
  • Loading branch information
violinday authored Jan 5, 2022
1 parent 6a36110 commit 976d588
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 158 deletions.
5 changes: 2 additions & 3 deletions example/lib/sample/components/tag/select_tag_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,7 @@ class SelectTagExamplePageState extends State<SelectTagExamplePage> {
double _getTagWidth(context, {int rowCount: 4}) {
double leftRightPadding = 40;
double rowSpace = 12;
return MediaQuery.of(context).size.width -
leftRightPadding -
rowSpace * (rowCount - 1) / rowCount;
return (MediaQuery.of(context).size.width - leftRightPadding - rowSpace * (rowCount - 1)) /
rowCount;
}
}
14 changes: 6 additions & 8 deletions lib/src/components/tag/brn_state_tag.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// @dart=2.9

import 'package:bruno/src/components/tag/brn_tag_custom.dart';
import 'package:flutter/material.dart';

Expand All @@ -17,17 +15,17 @@ import 'package:flutter/material.dart';
///
class BrnStateTag extends StatelessWidget {
final String tagText;
final Color backgroundColor;
final Color textColor;
final TagState tagState;
final Color? backgroundColor;
final Color? textColor;

//默认为等待状态,黄色
const BrnStateTag(
{Key key,
this.tagText,
{Key? key,
required this.tagText,
this.tagState = TagState.waiting,
this.backgroundColor,
this.textColor,
this.tagState = TagState.waiting})
this.textColor,})
: super(key: key);

@override
Expand Down
63 changes: 23 additions & 40 deletions lib/src/components/tag/brn_tag_custom.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// @dart=2.9

import 'package:bruno/src/theme/brn_theme_configurator.dart';
import 'package:flutter/material.dart';

Expand All @@ -22,10 +20,10 @@ class BrnTagCustom extends StatelessWidget {
final String tagText;

/// 标签的背景颜色 默认主题色
final Color backgroundColor;
final Color? backgroundColor;

/// 标签的文本颜色 默认F4的反白颜色
final Color textColor;
final Color? textColor;

/// 标签的圆角 默认为2
/// 如果同时设置了borderRadius、tagBorderRadius字段,优先使用tagBorderRadius字段设置圆角
Expand All @@ -44,15 +42,15 @@ class BrnTagCustom extends StatelessWidget {
final double maxWidth;

/// 标签边框
final Border border;
final Border? border;

BrnTagCustom({
Key key,
this.tagText,
Key? key,
required this.tagText,
this.textColor,
this.backgroundColor,
this.tagBorderRadius,
this.textPadding,
this.tagBorderRadius = const BorderRadius.all(Radius.circular(2)),
this.textPadding = const EdgeInsets.only(bottom: 0.5, left: 3, right: 3, top: 0),
this.border,
this.fontSize = 11,
this.fontWeight = FontWeight.normal,
Expand All @@ -61,61 +59,46 @@ class BrnTagCustom extends StatelessWidget {

///快捷方式生成边框标签
BrnTagCustom.buildBorderTag({
Key key,
Key? key,
required this.tagText,
this.backgroundColor = Colors.transparent,
this.tagText = "",
this.textPadding =
const EdgeInsets.only(bottom: 3, left: 3, right: 3, top: 0),
this.textPadding = const EdgeInsets.only(bottom: 3, left: 3, right: 3, top: 0),
this.fontSize = 11,
this.fontWeight = FontWeight.normal,
this.tagBorderRadius,
Color textColor,
Color borderColor,
this.tagBorderRadius = const BorderRadius.all(Radius.circular(2)),
Color? textColor,
Color? borderColor,
double borderWidth = 1,
double borderRadius = 3,
}) : this.maxWidth = double.infinity,
this.border = Border.all(
color: borderColor ??
BrnThemeConfigurator.instance
.getConfig()
.commonConfig
.brandPrimary,
width: borderWidth ?? 1,
color: borderColor ?? BrnThemeConfigurator.instance.getConfig().commonConfig.brandPrimary,
width: borderWidth,
),
this.textColor = textColor ??
BrnThemeConfigurator.instance.getConfig().commonConfig.brandPrimary,
this.textColor =
textColor ?? BrnThemeConfigurator.instance.getConfig().commonConfig.brandPrimary,
super(key: key);

@override
Widget build(BuildContext context) {
BorderRadius bRadius =
tagBorderRadius ?? BorderRadius.all(Radius.circular(2));
return Container(
constraints: BoxConstraints(
maxWidth: maxWidth,
),
decoration: BoxDecoration(
color: backgroundColor ??
BrnThemeConfigurator.instance
.getConfig()
.commonConfig
.brandPrimary,
BrnThemeConfigurator.instance.getConfig().commonConfig.brandPrimary,
shape: BoxShape.rectangle,
borderRadius: bRadius,
borderRadius: tagBorderRadius,
border: border),
padding: textPadding ??
EdgeInsets.only(bottom: 0.5, left: 3, right: 3, top: 0),
padding: textPadding,
child: Text(
tagText ?? "",
tagText,
textAlign: TextAlign.center,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontSize: fontSize ?? 11,
fontSize: fontSize,
color: textColor ??
BrnThemeConfigurator.instance
.getConfig()
.commonConfig
.colorTextBaseInverse,
BrnThemeConfigurator.instance.getConfig().commonConfig.colorTextBaseInverse,
fontWeight: fontWeight,
),
));
Expand Down
Loading

0 comments on commit 976d588

Please sign in to comment.