fix(ui): skip size animation entirely under reduced motion

This commit is contained in:
2026-10-24 13:07:20 +01:00
parent 4b9b93b443
commit 701449b416
2 changed files with 63 additions and 11 deletions
+17 -11
View File
@@ -73,22 +73,28 @@ class _CollapsibleListSectionState extends State<CollapsibleListSection> {
), ),
), ),
); );
final rows = _open
? Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: widget.children,
)
: const SizedBox(width: double.infinity);
final duration = Motion.of(context, Motion.standard);
return Column( return Column(
crossAxisAlignment: CrossAxisAlignment.stretch, crossAxisAlignment: CrossAxisAlignment.stretch,
children: [ children: [
Padding(padding: const EdgeInsets.only(top: 8), child: heading), Padding(padding: const EdgeInsets.only(top: 8), child: heading),
ClipRect( ClipRect(
child: AnimatedSize( // A zero-duration AnimatedSize can notify during its own layout when
duration: Motion.of(context, Motion.standard), // rows arrive asynchronously. Reduced motion should skip it entirely.
curve: Motion.curve, child: duration == Duration.zero
alignment: Alignment.topCenter, ? rows
child: _open : AnimatedSize(
? Column( duration: duration,
crossAxisAlignment: CrossAxisAlignment.stretch, curve: Motion.curve,
children: widget.children, alignment: Alignment.topCenter,
) child: rows,
: const SizedBox(width: double.infinity), ),
),
), ),
], ],
); );
@@ -0,0 +1,46 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/ui/layout/collapsible_list_section.dart';
void main() {
for (final cupertino in [false, true]) {
testWidgets(
'reduced-motion groups accept asynchronous row changes without layout animation ($cupertino)',
(tester) async {
tester.platformDispatcher.accessibilityFeaturesTestValue =
const FakeAccessibilityFeatures(disableAnimations: true);
addTearDown(
tester.platformDispatcher.clearAccessibilityFeaturesTestValue,
);
final rows = ValueNotifier<int>(1);
addTearDown(rows.dispose);
final body = ValueListenableBuilder<int>(
valueListenable: rows,
builder: (context, count, _) => SingleChildScrollView(
child: CollapsibleListSection(
title: 'Group',
count: count,
children: [for (var i = 0; i < count; i++) Text('Row $i')],
),
),
);
await tester.pumpWidget(
cupertino
? CupertinoApp(home: CupertinoPageScaffold(child: body))
: MaterialApp(home: Scaffold(body: body)),
);
await tester.pumpAndSettle();
rows.value = 3;
await tester.pumpAndSettle();
expect(find.text('Row 2'), findsOneWidget);
expect(find.byType(AnimatedSize), findsNothing);
expect(tester.takeException(), isNull);
await tester.tap(find.text('Group'));
await tester.pumpAndSettle();
expect(find.text('Row 0'), findsNothing);
expect(tester.takeException(), isNull);
},
);
}
}