-
Notifications
You must be signed in to change notification settings - Fork 504
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 card_title to null safety #59
Merged
zhoujuanjuan
merged 4 commits into
LianjiaTech:null-safe
from
laiiihz:null-safe-card-title
Jan 10, 2022
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
afb94ff
migrate card_title to null-safety
laiiihz 075ae8c
[fix] brn_action_card_title: _sub widget is not null
laiiihz 23cd534
[optimize] empty widget use SizedBox instead of Container
laiiihz 5b78d9e
replace empty widget SizedBox to SizedBox.shrink
laiiihz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
// @dart=2.9 | ||
|
||
import 'package:bruno/src/theme/base/brn_text_style.dart'; | ||
import 'package:bruno/src/theme/brn_theme_configurator.dart'; | ||
import 'package:bruno/src/theme/configs/brn_card_title_config.dart'; | ||
|
@@ -52,34 +50,34 @@ class BrnCommonCardTitle extends StatelessWidget { | |
final String title; | ||
|
||
/// 最右侧的文字 | ||
final String accessoryText; | ||
final String? accessoryText; | ||
|
||
/// 最右侧的widget 如果两者同时存在 则以widget为主 | ||
final Widget accessoryWidget; | ||
final Widget? accessoryWidget; | ||
|
||
/// 整个区域点击的回调 | ||
final VoidCallback onTap; | ||
final VoidCallback? onTap; | ||
|
||
/// 标题右侧的显示widget | ||
final Widget subTitleWidget; | ||
final Widget? subTitleWidget; | ||
|
||
/// 标题下面的文字 | ||
final String detailTextString; | ||
final String? detailTextString; | ||
|
||
/// title的流式文本的对齐方式 | ||
final PlaceholderAlignment alignment; | ||
final PlaceholderAlignment? alignment; | ||
|
||
/// 标题下方文字 默认是深色的222222 | ||
final Color detailColor; | ||
final Color? detailColor; | ||
|
||
/// 内容的padding 默认上下16 左右0 | ||
final EdgeInsetsGeometry padding; | ||
final EdgeInsetsGeometry? padding; | ||
|
||
final BrnCardTitleConfig themeData; | ||
final BrnCardTitleConfig? themeData; | ||
|
||
BrnCommonCardTitle( | ||
{Key key, | ||
@required this.title, | ||
{Key? key, | ||
required this.title, | ||
this.accessoryText, | ||
this.accessoryWidget, | ||
this.onTap, | ||
|
@@ -97,35 +95,30 @@ class BrnCommonCardTitle extends StatelessWidget { | |
|
||
defaultConfig = defaultConfig.merge(BrnCardTitleConfig( | ||
alignment: alignment, | ||
cardTitlePadding: padding, | ||
cardTitlePadding: padding as EdgeInsets?, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. mark |
||
detailTextStyle: BrnTextStyle(color: detailColor))); | ||
|
||
defaultConfig = BrnThemeConfigurator.instance | ||
.getConfig(configId: defaultConfig.configId) | ||
.cardTitleConfig | ||
.merge(defaultConfig); | ||
|
||
Widget titleContainer = Container( | ||
color: defaultConfig.cardBackgroundColor, | ||
child: _rowWidget(context, defaultConfig), | ||
); | ||
if (onTap == null) return titleContainer; | ||
return GestureDetector( | ||
onTap: () { | ||
if (onTap != null) { | ||
onTap(); | ||
} | ||
}, | ||
child: Container( | ||
color: defaultConfig?.cardBackgroundColor, | ||
child: _rowWidget(context, defaultConfig), | ||
), | ||
onTap: onTap, | ||
child: titleContainer, | ||
); | ||
} | ||
|
||
Widget _rowWidget(BuildContext context, BrnCardTitleConfig defaultConfig) { | ||
List<Widget> children = List<Widget>(); | ||
List<Widget> children = []; | ||
children.add(Expanded(child: _titleWidget(context, defaultConfig))); | ||
|
||
Widget accessory = Container( | ||
height: 0, | ||
width: 0, | ||
); | ||
Widget accessory = SizedBox(); | ||
// 左侧的文本的行高是25,那么右侧的widget最大为25 | ||
if (this.accessoryWidget != null) { | ||
accessory = Container( | ||
|
@@ -153,7 +146,7 @@ class BrnCommonCardTitle extends StatelessWidget { | |
Widget _accessoryTextWidget(BrnCardTitleConfig defaultConfig) { | ||
Text tx = Text( | ||
accessoryText ?? "", | ||
style: defaultConfig?.accessoryTextStyle?.generateTextStyle(), | ||
style: defaultConfig.accessoryTextStyle.generateTextStyle(), | ||
); | ||
|
||
return Container( | ||
|
@@ -174,28 +167,25 @@ class BrnCommonCardTitle extends StatelessWidget { | |
|
||
///标题widget | ||
Widget _titleWidget(BuildContext context, BrnCardTitleConfig defaultConfig) { | ||
Widget subWidget = Container( | ||
height: 0, | ||
width: 0, | ||
); | ||
Widget subWidget = SizedBox(height: 0, width: 0); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 同上~ |
||
|
||
if (subTitleWidget != null) { | ||
subWidget = _subTitleWidgetFromWidget(); | ||
} | ||
var titleWidget = RichText( | ||
textScaleFactor: MediaQuery.of(context)?.textScaleFactor ?? 1.0, | ||
textScaleFactor: MediaQuery.of(context).textScaleFactor, | ||
text: TextSpan( | ||
text: title ?? "", | ||
style: defaultConfig?.titleWithHeightTextStyle?.generateTextStyle(), | ||
text: title, | ||
style: defaultConfig.titleWithHeightTextStyle.generateTextStyle(), | ||
children: <InlineSpan>[ | ||
WidgetSpan(child: subWidget, alignment: defaultConfig.alignment), | ||
]), | ||
); | ||
|
||
List<Widget> colChildren = List<Widget>(); | ||
List<Widget> colChildren = []; | ||
colChildren.add(titleWidget); | ||
|
||
if (null != detailTextString && detailTextString.isNotEmpty) { | ||
if (null != detailTextString && detailTextString!.isNotEmpty) { | ||
Widget detailWidget = _detailTextWidget(defaultConfig); | ||
colChildren.add(detailWidget); | ||
} | ||
|
@@ -214,7 +204,7 @@ class BrnCommonCardTitle extends StatelessWidget { | |
detailTextString ?? "", | ||
overflow: TextOverflow.ellipsis, | ||
maxLines: 2, | ||
style: defaultConfig?.detailTextStyle?.generateTextStyle(), | ||
style: defaultConfig.detailTextStyle.generateTextStyle(), | ||
); | ||
return Container( | ||
child: tx, | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
推荐使用 SizedBox.shrink ~
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍