diff --git a/lib/src/components/appraise/brn_appraise_bottom_picker.dart b/lib/src/components/appraise/brn_appraise_bottom_picker.dart index 10344ce7..753d45cf 100644 --- a/lib/src/components/appraise/brn_appraise_bottom_picker.dart +++ b/lib/src/components/appraise/brn_appraise_bottom_picker.dart @@ -1,7 +1,7 @@ -import 'package:bruno/bruno.dart'; import 'package:bruno/src/components/appraise/brn_appraise.dart'; import 'package:bruno/src/components/appraise/brn_appraise_header.dart'; import 'package:bruno/src/components/appraise/brn_appraise_config.dart'; +import 'package:bruno/src/l10n/brn_intl.dart'; import 'package:flutter/material.dart'; import 'package:bruno/src/components/appraise/brn_appraise_interface.dart'; diff --git a/lib/src/components/dialog/brn_middle_input_diaolg.dart b/lib/src/components/dialog/brn_middle_input_diaolg.dart index 259c2d5b..6718d706 100644 --- a/lib/src/components/dialog/brn_middle_input_diaolg.dart +++ b/lib/src/components/dialog/brn_middle_input_diaolg.dart @@ -1,5 +1,5 @@ -import 'package:bruno/bruno.dart'; import 'package:bruno/src/components/dialog/brn_dialog.dart'; +import 'package:bruno/src/l10n/brn_intl.dart'; import 'package:bruno/src/theme/brn_theme.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; diff --git a/lib/src/components/dialog/brn_safe_dialog.dart b/lib/src/components/dialog/brn_safe_dialog.dart index 8551dc3f..405c606f 100644 --- a/lib/src/components/dialog/brn_safe_dialog.dart +++ b/lib/src/components/dialog/brn_safe_dialog.dart @@ -1,6 +1,5 @@ import 'dart:async'; -import 'package:bruno/bruno.dart'; import 'package:flutter/material.dart'; /// * * * * * * * * * * * diff --git a/lib/src/components/form/items/general/brn_radio_portrait_input_item.dart b/lib/src/components/form/items/general/brn_radio_portrait_input_item.dart index d0000f13..9bc71096 100644 --- a/lib/src/components/form/items/general/brn_radio_portrait_input_item.dart +++ b/lib/src/components/form/items/general/brn_radio_portrait_input_item.dart @@ -1,5 +1,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/line/brn_line.dart'; +import 'package:bruno/src/components/radio/brn_radio_button.dart'; +import 'package:bruno/src/theme/brn_theme.dart'; import 'package:flutter/material.dart'; /// diff --git a/lib/src/components/form/items/general/brn_step_input_item.dart b/lib/src/components/form/items/general/brn_step_input_item.dart index e5533508..f7808421 100644 --- a/lib/src/components/form/items/general/brn_step_input_item.dart +++ b/lib/src/components/form/items/general/brn_step_input_item.dart @@ -1,6 +1,10 @@ -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/constants/brn_asset_constants.dart'; import 'package:bruno/src/constants/brn_fonts_constants.dart'; +import 'package:bruno/src/theme/brn_theme.dart'; +import 'package:bruno/src/utils/brn_tools.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; diff --git a/lib/src/components/form/items/general/brn_text_select_item.dart b/lib/src/components/form/items/general/brn_text_select_item.dart index 52aaeff9..7c19b64a 100644 --- a/lib/src/components/form/items/general/brn_text_select_item.dart +++ b/lib/src/components/form/items/general/brn_text_select_item.dart @@ -2,9 +2,9 @@ import 'dart:math'; -import 'package:bruno/bruno.dart'; import 'package:bruno/src/components/form/base/brn_form_item_type.dart'; import 'package:bruno/src/components/form/utils/brn_form_util.dart'; +import 'package:bruno/src/l10n/brn_intl.dart'; import 'package:bruno/src/theme/brn_theme_configurator.dart'; import 'package:bruno/src/theme/configs/brn_form_config.dart'; import 'package:bruno/src/utils/brn_tools.dart'; diff --git a/lib/src/components/loading/brn_loading.dart b/lib/src/components/loading/brn_loading.dart index a9ae87ee..17b10cf8 100644 --- a/lib/src/components/loading/brn_loading.dart +++ b/lib/src/components/loading/brn_loading.dart @@ -1,4 +1,4 @@ -import 'package:bruno/bruno.dart'; +import 'package:bruno/src/components/dialog/brn_safe_dialog.dart'; import 'package:bruno/src/l10n/brn_intl.dart'; import 'package:flutter/material.dart'; diff --git a/lib/src/components/picker/base/brn_picker_title_config.dart b/lib/src/components/picker/base/brn_picker_title_config.dart index 72133b0c..bdd12b30 100755 --- a/lib/src/components/picker/base/brn_picker_title_config.dart +++ b/lib/src/components/picker/base/brn_picker_title_config.dart @@ -1,4 +1,3 @@ -import 'package:bruno/bruno.dart'; import 'package:flutter/material.dart'; import 'package:bruno/src/components/picker/base/brn_picker_constants.dart'; diff --git a/lib/src/components/radio/brn_checkbox.dart b/lib/src/components/radio/brn_checkbox.dart index 02d97efb..881a009d 100644 --- a/lib/src/components/radio/brn_checkbox.dart +++ b/lib/src/components/radio/brn_checkbox.dart @@ -1,4 +1,6 @@ -import 'package:bruno/bruno.dart'; +import 'package:bruno/src/components/radio/brn_radio_core.dart'; +import 'package:bruno/src/constants/brn_asset_constants.dart'; +import 'package:bruno/src/utils/brn_tools.dart'; import 'package:flutter/material.dart'; ///多选按钮 diff --git a/lib/src/components/radio/brn_radio_button.dart b/lib/src/components/radio/brn_radio_button.dart index 071f229b..9bea437b 100644 --- a/lib/src/components/radio/brn_radio_button.dart +++ b/lib/src/components/radio/brn_radio_button.dart @@ -1,4 +1,6 @@ -import 'package:bruno/bruno.dart'; +import 'package:bruno/src/components/radio/brn_radio_core.dart'; +import 'package:bruno/src/constants/brn_asset_constants.dart'; +import 'package:bruno/src/utils/brn_tools.dart'; import 'package:flutter/material.dart'; ///单选按钮 diff --git a/lib/src/components/selection/brn_flat_selection.dart b/lib/src/components/selection/brn_flat_selection.dart index aebdefcf..0721a30d 100644 --- a/lib/src/components/selection/brn_flat_selection.dart +++ b/lib/src/components/selection/brn_flat_selection.dart @@ -1,6 +1,5 @@ import 'dart:async'; -import 'package:bruno/bruno.dart'; import 'package:bruno/src/components/popup/brn_measure_size.dart'; import 'package:bruno/src/components/selection/bean/brn_selection_common_entity.dart'; import 'package:bruno/src/components/selection/brn_selection_util.dart'; @@ -9,6 +8,7 @@ import 'package:bruno/src/components/selection/controller/brn_flat_selection_con import 'package:bruno/src/components/selection/converter/brn_selection_converter.dart'; import 'package:bruno/src/components/selection/widget/brn_flat_selection_item.dart'; import 'package:bruno/src/components/toast/brn_toast.dart'; +import 'package:bruno/src/l10n/brn_intl.dart'; import 'package:bruno/src/theme/brn_theme_configurator.dart'; import 'package:bruno/src/theme/configs/brn_selection_config.dart'; import 'package:flutter/material.dart'; diff --git a/lib/src/components/tabbar/bottom/brn_bottom_tab_bar_main.dart b/lib/src/components/tabbar/bottom/brn_bottom_tab_bar_main.dart index 6d2a3454..8d8c1e7f 100644 --- a/lib/src/components/tabbar/bottom/brn_bottom_tab_bar_main.dart +++ b/lib/src/components/tabbar/bottom/brn_bottom_tab_bar_main.dart @@ -3,7 +3,8 @@ import 'dart:collection' show Queue; import 'dart:math' as math; -import 'package:bruno/bruno.dart'; +import 'package:bruno/src/components/tabbar/bottom/brn_bottom_tab_bar_item.dart'; +import 'package:bruno/src/theme/brn_theme.dart'; import 'package:flutter/material.dart'; /// 定义一些UI常量,根据UI稿进行填写 diff --git a/lib/src/components/tabbar/normal/brn_tab_bar.dart b/lib/src/components/tabbar/normal/brn_tab_bar.dart index 8a4feb42..02bc9f5a 100644 --- a/lib/src/components/tabbar/normal/brn_tab_bar.dart +++ b/lib/src/components/tabbar/normal/brn_tab_bar.dart @@ -1,4 +1,3 @@ -import 'package:badges/badges.dart'; import 'package:bruno/src/components/popup/brn_measure_size.dart'; import 'package:bruno/src/components/tabbar/indicator/brn_custom_width_indicator.dart'; import 'package:bruno/src/components/tabbar/normal/brn_tabbar_controller.dart'; @@ -168,24 +167,21 @@ enum BrnTabBarBadgeMode { } class BrnTabBarState extends State { - /// 小红点容器的样式 - late BadgeShape _badgeShape; - /// 小红点文案 late String _badgeText; /// 小红点容器内边距 late EdgeInsets _badgePadding; + /// 小红点高度 + late double _largeSize; + /// 小红点上偏移量 double _paddingTop = 0; /// 小红点右偏移量 double _paddingRight = 0; - /// 小红点圆角 - late BorderRadiusGeometry _borderRadius; - /// 展开更多的按钮宽度 final double _moreSpacing = 50; @@ -382,46 +378,51 @@ class BrnTabBarState extends State { // 原始的自适应的tab样式 Widget _wrapOriginWidget( BadgeTab badgeTab, bool lastElement, bool isScrollable) { - caculateBadgeParams(badgeTab); - var _contentWidget = Container( - alignment: Alignment.center, - height: 47, - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Visibility( - visible: widget.hasIndex && badgeTab.topText != null, + var _contentWidget = LayoutBuilder(builder: (context, constraints) { + caculateBadgeParams(badgeTab, constraints); + return Container( + alignment: Alignment.center, + height: 47, + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Visibility( + visible: widget.hasIndex && badgeTab.topText != null, + child: Text( + badgeTab.topText ?? "", + maxLines: 1, + overflow: TextOverflow.ellipsis, + )), + Badge( + isLabelVisible: (badgeTab.badgeNum != null + ? badgeTab.badgeNum! > 0 + : false) || + badgeTab.showRedBadge || + (badgeTab.badgeText != null + ? badgeTab.badgeText!.isNotEmpty + : false), + label: Text( + _badgeText, + style: TextStyle( + color: Color(0xFFFFFFFF), fontSize: 10, height: 1), + ), + backgroundColor: Colors.red, + alignment: AlignmentDirectional(_paddingRight, _paddingTop), + padding: _badgePadding, + largeSize: _largeSize, child: Text( - badgeTab.topText ?? "", + badgeTab.text!, maxLines: 1, + softWrap: true, + textAlign: TextAlign.center, overflow: TextOverflow.ellipsis, - )), - Badge( - showBadge: - (badgeTab.badgeNum != null ? badgeTab.badgeNum! > 0 : false) || - badgeTab.showRedBadge || - (badgeTab.badgeText != null - ? badgeTab.badgeText!.isNotEmpty - : false), - badgeContent: Text( - _badgeText, - style: - TextStyle(color: Color(0xFFFFFFFF), fontSize: 10, height: 1), - ), - shape: _badgeShape, - elevation: 0, - toAnimate: false, - borderRadius: _borderRadius, - alignment: Alignment.topLeft, - padding: _badgePadding, - position: - BadgePosition.topEnd(top: _paddingTop, end: _paddingRight), - child: Text(badgeTab.text!, - maxLines: 1, softWrap: true, overflow: TextOverflow.ellipsis), - ) - ], - ), - ); + style: TextStyle(fontSize: 16), + ), + ) + ], + ), + ); + }); return Row( mainAxisAlignment: MainAxisAlignment.center, children: [ @@ -445,114 +446,138 @@ class BrnTabBarState extends State { // 定制的等分tab样式 Widget _wrapAverageWidget( BadgeTab badgeTab, double? minWidth, bool lastElement) { - caculateBadgeParams(badgeTab); - return Container( - width: minWidth, - alignment: Alignment.center, - child: Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Expanded( + return LayoutBuilder(builder: (context, constraints) { + caculateBadgeParams(badgeTab, constraints); + return Container( + width: minWidth, + alignment: Alignment.center, + child: Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Expanded( + child: Container( + alignment: Alignment.center, + height: 47, + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Visibility( + visible: widget.hasIndex && badgeTab.topText != null, + child: Text( + badgeTab.topText ?? "", + maxLines: 1, + overflow: TextOverflow.ellipsis, + )), + Badge( + isLabelVisible: (badgeTab.badgeNum != null + ? badgeTab.badgeNum! > 0 + : false) || + badgeTab.showRedBadge || + (badgeTab.badgeText != null + ? badgeTab.badgeText!.isNotEmpty + : false), + backgroundColor: Colors.red, + label: Text( + _badgeText, + style: TextStyle( + color: Color(0xFFFFFFFF), fontSize: 10, height: 1), + ), + alignment: AlignmentDirectional(_paddingRight, _paddingTop), + padding: _badgePadding, + largeSize: _largeSize, + child: Text(badgeTab.text!, + textAlign: TextAlign.center, + maxLines: 1, + softWrap: true, + overflow: TextOverflow.ellipsis, + style: TextStyle(fontSize: 16)), + ) + ], + ), + )), + Visibility( + visible: widget.hasDivider && !lastElement, child: Container( - alignment: Alignment.center, - height: 47, - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Visibility( - visible: widget.hasIndex && badgeTab.topText != null, - child: Text( - badgeTab.topText ?? "", - maxLines: 1, - overflow: TextOverflow.ellipsis, - )), - Badge( - showBadge: (badgeTab.badgeNum != null - ? badgeTab.badgeNum! > 0 - : false) || - badgeTab.showRedBadge || - (badgeTab.badgeText != null - ? badgeTab.badgeText!.isNotEmpty - : false), - badgeContent: Text( - _badgeText, - style: TextStyle( - color: Color(0xFFFFFFFF), fontSize: 10, height: 1), - ), - shape: _badgeShape, - elevation: 0, - toAnimate: false, - borderRadius: _borderRadius, - alignment: Alignment.topLeft, - padding: _badgePadding, - position: BadgePosition.topEnd( - top: _paddingTop, end: _paddingRight), - child: Text(badgeTab.text!, - maxLines: 1, - softWrap: true, - overflow: TextOverflow.ellipsis), - ) - ], - ), - )), - Visibility( - visible: widget.hasDivider && !lastElement, - child: Container( - width: 1, - height: 20, - color: Color(0xffe4e6f0), - ), - ) - ], - ), - ); + width: 1, + height: 20, + color: Color(0xffe4e6f0), + ), + ) + ], + ), + ); + }); } // 计算小红点尺寸相关参数 - void caculateBadgeParams(BadgeTab badgeTab) { + void caculateBadgeParams(BadgeTab badgeTab, BoxConstraints constraints) { + _paddingTop = -5.0; + if (badgeTab.badgeNum != null) { if (badgeTab.badgeNum! < 10) { - _badgePadding = EdgeInsets.all(5); - _badgeShape = BadgeShape.circle; + _badgePadding = EdgeInsets.only(left: 5.0, right: 5.0); + _largeSize = 16.0; _badgeText = badgeTab.badgeNum?.toString() ?? ""; - _paddingTop = -8; - _paddingRight = -18; - _borderRadius = BorderRadius.all(Radius.circular(8.5)); } else if (badgeTab.badgeNum! > 99) { _badgePadding = EdgeInsets.fromLTRB(4, 3, 4, 2); - _badgeShape = BadgeShape.square; + _largeSize = 16.0; _badgeText = "99+"; - _paddingRight = -27; - _paddingTop = -5; - _borderRadius = BorderRadius.all(Radius.circular(8.5)); } else { _badgePadding = EdgeInsets.fromLTRB(4, 3, 4, 2); - _badgeShape = BadgeShape.square; + _largeSize = 16.0; _badgeText = badgeTab.badgeNum?.toString() ?? ""; - _paddingTop = -5; - _paddingRight = -20; - _borderRadius = BorderRadius.all(Radius.circular(8.5)); } } else { if (badgeTab.badgeText != null && badgeTab.badgeText!.isNotEmpty) { - _badgePadding = EdgeInsets.fromLTRB(5, 3, 5, 2); - _badgeShape = BadgeShape.square; + _badgePadding = EdgeInsets.fromLTRB(6, 3, 6, 3); + _largeSize = 16.0; _badgeText = badgeTab.badgeText?.toString() ?? ""; - _paddingTop = -5; - _paddingRight = -20; - _borderRadius = BorderRadius.only( - topLeft: Radius.circular(8.5), - topRight: Radius.circular(8.5), - bottomRight: Radius.circular(8.5), - bottomLeft: Radius.circular(0)); } else { - _badgePadding = EdgeInsets.all(4); - _badgeShape = BadgeShape.circle; + _badgePadding = EdgeInsets.only(left: 4.0, right: 4.0); + _largeSize = 8.0; _badgeText = ""; - _paddingRight = -8; - _borderRadius = BorderRadius.all(Radius.circular(8.5)); + _paddingTop = 1.0; } } + + // 获取 tabTextWidth + TextStyle tabTextStyle = + TextStyle(overflow: TextOverflow.ellipsis, fontSize: 16); + TextPainter _tabTextPainter = TextPainter( + locale: Localizations.localeOf(context), textAlign: TextAlign.center); + _tabTextPainter.textDirection = TextDirection.ltr; + _tabTextPainter.maxLines = 1; + _tabTextPainter.text = TextSpan(text: badgeTab.text, style: tabTextStyle); + _tabTextPainter.layout(maxWidth: constraints.maxWidth); + double _tabTextWidth = _tabTextPainter.width; + + // 获取 badgeTextWidth + TextStyle badgeTextStyle = TextStyle(height: 1, fontSize: 10); + TextPainter _badgeTextPainter = + TextPainter(textScaleFactor: MediaQuery.of(context).textScaleFactor); + _badgeTextPainter.textDirection = TextDirection.ltr; + _badgeTextPainter.maxLines = 1; + _badgeTextPainter.text = TextSpan(text: _badgeText, style: badgeTextStyle); + _badgeTextPainter.layout(maxWidth: constraints.maxWidth); + // 红点内 text 的宽度 + double _badgeTextWidth = _badgeTextPainter.width; + + double _badgeWidth = _badgeTextWidth + _badgePadding.horizontal; + + // 获取外部传入的tab padding值 + EdgeInsets _labelPadding = widget.labelPadding.resolve(TextDirection.ltr); + + if ((_tabTextWidth + _badgeWidth) > + (constraints.maxWidth + _labelPadding.right)) { + // 如果tab文字宽度 + 红点宽度 > 约束宽度(父容器宽度)+ 设置tab 右padding 则将红点左移 红点宽度偏移量 + // if(_badgeWidth > (constraints.maxWidth + _labelPadding.right)){ + // _paddingRight = 0.0; + // }else{ + _paddingRight = constraints.maxWidth + _labelPadding.right - _badgeWidth; + // } + } else { + _paddingRight = _tabTextWidth; + } } // 展开更多 @@ -615,7 +640,7 @@ class BrnTabBarState extends State { resetEntry(); } _brnTabbarController.entry = overlayEntry; - Overlay.of(context)!.insert(_brnTabbarController.entry!); + Overlay.of(context).insert(_brnTabbarController.entry!); } void resetEntry() { diff --git a/lib/src/l10n/brn_intl.dart b/lib/src/l10n/brn_intl.dart index 4b1359ad..a0f82d94 100644 --- a/lib/src/l10n/brn_intl.dart +++ b/lib/src/l10n/brn_intl.dart @@ -39,7 +39,7 @@ class BrnIntl { /// 获取[BrnIntl]实例 static BrnIntl of(BuildContext context) { - return Localizations.of(context, BrnIntl); + return Localizations.of(context, BrnIntl) ?? BrnIntl(BrnResourceZh.locale); } /// 获取当前语言下 [BrnBaseResource] 资源 diff --git a/pubspec.yaml b/pubspec.yaml index 5d2268ab..63dea0bb 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: bruno description: An enterprise-class package of Flutter components for mobile applications. -version: 3.2.0 +version: 3.2.1 homepage: https://github.com/LianjiaTech/bruno environment: @@ -16,7 +16,6 @@ dependencies: flutter_easyrefresh: ^2.2.1 intl: ^0.17.0 photo_view: ^0.14.0 - badges: ^2.0.2 bindings_compatible: ^1.0.1 dev_dependencies: