merge: 修正窄筛选行横向居中

This commit is contained in:
Zhou Weidong committed 2026-10-22 20:59:14 +08:00
commit 3655d94869
2 files changed
+52 -42

No files matched your search

+2
View File
@@ -1220,3 +1220,5 @@ $ flutter test
- 第 4 行仅最热/最新在滚动区内,44 圆形筛选按钮固定在滚动区外;`flutter analyze` 无问题。 - 第 4 行仅最热/最新在滚动区内,44 圆形筛选按钮固定在滚动区外;`flutter analyze` 无问题。
- 四行统一复用 `_filterRow` 构建,筛选区仅保留一层左右 12 padding。 - 四行统一复用 `_filterRow` 构建,筛选区仅保留一层左右 12 padding。
- 新增量化测试断言四行首项 x 均为 12、相邻 chip 间距均为 10;`flutter analyze` 无问题。 - 新增量化测试断言四行首项 x 均为 12、相邻 chip 间距均为 10;`flutter analyze` 无问题。
- 修复横向 viewport 对短内容居中:滚动内容最小宽度撑满视口后由 Row.start 排列。
- `flutter test test/recommend/all_dramas_filter_alignment_test.dart`:1 项测试通过。
@@ -186,26 +186,41 @@ class _AllDramasFilterGridState extends State<AllDramasFilterGrid> {
}) { }) {
return _filterRow( return _filterRow(
row: row, row: row,
child: SingleChildScrollView( child: _horizontalChipScroll(
key: Key('all-filter-scroll-$row'), scrollKey: Key('all-filter-scroll-$row'),
chips: [
for (var index = 0; index < options.length; index++) ...[
_chip(
key: Key('all-filter-${options[index].id}'),
label: options[index].label,
selected: selected == options[index].id,
onTap: () => onSelected(options[index].id),
),
if (index < options.length - 1)
const SizedBox(width: AppDimens.filterItemGap),
],
],
),
);
}
Widget _horizontalChipScroll({
required Key scrollKey,
required List<Widget> chips,
}) {
return LayoutBuilder(
builder: (context, constraints) => SingleChildScrollView(
key: scrollKey,
scrollDirection: Axis.horizontal, scrollDirection: Axis.horizontal,
physics: const BouncingScrollPhysics(), physics: const BouncingScrollPhysics(),
child: Row( child: ConstrainedBox(
mainAxisSize: MainAxisSize.min, constraints: BoxConstraints(minWidth: constraints.maxWidth),
mainAxisAlignment: MainAxisAlignment.start, child: Row(
crossAxisAlignment: CrossAxisAlignment.center, mainAxisSize: MainAxisSize.min,
children: [ mainAxisAlignment: MainAxisAlignment.start,
for (var index = 0; index < options.length; index++) ...[ crossAxisAlignment: CrossAxisAlignment.center,
_chip( children: chips,
key: Key('all-filter-${options[index].id}'), ),
label: options[index].label,
selected: selected == options[index].id,
onTap: () => onSelected(options[index].id),
),
if (index < options.length - 1)
const SizedBox(width: AppDimens.filterItemGap),
],
],
), ),
), ),
); );
@@ -286,30 +301,23 @@ class _AllDramasFilterGridState extends State<AllDramasFilterGrid> {
crossAxisAlignment: CrossAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center,
children: [ children: [
Expanded( Expanded(
child: SingleChildScrollView( child: _horizontalChipScroll(
key: const Key('all-filter-scroll-3'), scrollKey: const Key('all-filter-scroll-3'),
scrollDirection: Axis.horizontal, chips: [
physics: const BouncingScrollPhysics(), _chip(
child: Row( key: const Key('all-sort-hot'),
mainAxisSize: MainAxisSize.min, label: l10n.hot,
mainAxisAlignment: MainAxisAlignment.start, selected: !_newest,
crossAxisAlignment: CrossAxisAlignment.center, onTap: () => setState(() => _newest = false),
children: [ ),
_chip( const SizedBox(width: AppDimens.filterItemGap),
key: const Key('all-sort-hot'), _chip(
label: l10n.hot, key: const Key('all-sort-new'),
selected: !_newest, label: l10n.newest,
onTap: () => setState(() => _newest = false), selected: _newest,
), onTap: () => setState(() => _newest = true),
const SizedBox(width: AppDimens.filterItemGap), ),
_chip( ],
key: const Key('all-sort-new'),
label: l10n.newest,
selected: _newest,
onTap: () => setState(() => _newest = true),
),
],
),
), ),
), ),
const SizedBox(width: AppDimens.filterItemGap), const SizedBox(width: AppDimens.filterItemGap),