From afd58f7efd1449b2b68d6d21e6f2125317311f80 Mon Sep 17 00:00:00 2001 From: zhaojian Date: Mon, 14 Jul 2025 14:43:10 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=B0=86View.of(context)=20=E8=B0=83?= =?UTF-8?q?=E7=94=A8=E4=BB=8EinitState=E7=A7=BB=E5=8A=A8=E5=88=B0didChange?= =?UTF-8?q?Dependencies=EF=BC=8C=E4=BF=AE=E5=A4=8D=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../widget/brn_selection_range_widget.dart | 45 ++++++++++--------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/lib/src/components/selection/widget/brn_selection_range_widget.dart b/lib/src/components/selection/widget/brn_selection_range_widget.dart index d1d8cc89..a729f79e 100644 --- a/lib/src/components/selection/widget/brn_selection_range_widget.dart +++ b/lib/src/components/selection/widget/brn_selection_range_widget.dart @@ -1,4 +1,3 @@ - import 'package:bruno/src/components/button/brn_big_main_button.dart'; import 'package:bruno/src/components/calendar/brn_calendar_view.dart'; import 'package:bruno/src/components/line/brn_line.dart'; @@ -82,7 +81,7 @@ class _BrnRangeSelectionGroupWidgetState @override void initState() { - _screenWidth = View.of(context).physicalSize.width / View.of(context).devicePixelRatio; + super.initState(); _initData(); _tabController = TabController(vsync: this, length: _firstList.length); if (_firstIndex >= 0) { @@ -94,7 +93,13 @@ class _BrnRangeSelectionGroupWidgetState ? _firstList : _firstList[_tabController.index].children); }); - super.initState(); + } + + @override + void didChangeDependencies() { + super.didChangeDependencies(); + _screenWidth = + View.of(context).physicalSize.width / View.of(context).devicePixelRatio; } @override @@ -237,14 +242,10 @@ class _BrnRangeSelectionGroupWidgetState ///如果指定展示列,则按照指定列展示,否则动态计算宽度。最大不超过四列。 if (widget.rowCount == null) { - int oneCountTagWidth = - (_screenWidth - 40 - 12 * (1 - 1)) ~/ 1; - int twoCountTagWidth = - (_screenWidth - 40 - 12 * (2 - 1)) ~/ 2; - int threeCountTagWidth = - (_screenWidth - 40 - 12 * (3 - 1)) ~/ 3; - int fourCountTagWidth = - (_screenWidth - 40 - 12 * (4 - 1)) ~/ 4; + int oneCountTagWidth = (_screenWidth - 40 - 12 * (1 - 1)) ~/ 1; + int twoCountTagWidth = (_screenWidth - 40 - 12 * (2 - 1)) ~/ 2; + int threeCountTagWidth = (_screenWidth - 40 - 12 * (3 - 1)) ~/ 3; + int fourCountTagWidth = (_screenWidth - 40 - 12 * (4 - 1)) ~/ 4; if (maxWidthSize.width > twoCountTagWidth) { tagWidth = oneCountTagWidth; } else if (threeCountTagWidth < maxWidthSize.width && @@ -257,10 +258,8 @@ class _BrnRangeSelectionGroupWidgetState tagWidth = fourCountTagWidth; } } else { - tagWidth = (_screenWidth - - 40 - - 12 * (widget.rowCount! - 1)) ~/ - widget.rowCount!; + tagWidth = + (_screenWidth - 40 - 12 * (widget.rowCount! - 1)) ~/ widget.rowCount!; } var tagContainer = tagFilterList.isNotEmpty @@ -435,12 +434,15 @@ class _BrnRangeSelectionGroupWidgetState if (!rangeEntity.isValidRange()) { FocusScope.of(context).requestFocus(FocusNode()); if (rangeEntity.filterType == BrnSelectionFilterType.range) { - BrnToast.show(BrnIntl.of(context).localizedResource.enterRangeError, context); + BrnToast.show( + BrnIntl.of(context).localizedResource.enterRangeError, context); } else if (rangeEntity.filterType == BrnSelectionFilterType.dateRange || rangeEntity.filterType == BrnSelectionFilterType.dateRangeCalendar) { - BrnToast.show(BrnIntl.of(context).localizedResource.selectRangeError, context); + BrnToast.show( + BrnIntl.of(context).localizedResource.selectRangeError, + context); } return; } @@ -664,10 +666,11 @@ class _BrnRangeSelectionGroupWidgetState bool _hasCalendarItem(BrnSelectionEntity entity) { bool hasCalendarItem = false; hasCalendarItem = entity.children - .where((_) => - _.filterType == BrnSelectionFilterType.date || - _.filterType == BrnSelectionFilterType.dateRangeCalendar) - .toList().isNotEmpty; + .where((_) => + _.filterType == BrnSelectionFilterType.date || + _.filterType == BrnSelectionFilterType.dateRangeCalendar) + .toList() + .isNotEmpty; /// 查找第二层级 if (!hasCalendarItem) {