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 BrnStateTag、BrnTagCustom、BrnSelectTag、BrnDeleteTag to null-safe #46

Merged
merged 2 commits into from
Jan 5, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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