fix(ui): skip size animation entirely under reduced motion
This commit is contained in:
@@ -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(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Padding(padding: const EdgeInsets.only(top: 8), child: heading),
|
||||
ClipRect(
|
||||
child: AnimatedSize(
|
||||
duration: Motion.of(context, Motion.standard),
|
||||
curve: Motion.curve,
|
||||
alignment: Alignment.topCenter,
|
||||
child: _open
|
||||
? Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: widget.children,
|
||||
)
|
||||
: const SizedBox(width: double.infinity),
|
||||
),
|
||||
// A zero-duration AnimatedSize can notify during its own layout when
|
||||
// rows arrive asynchronously. Reduced motion should skip it entirely.
|
||||
child: duration == Duration.zero
|
||||
? rows
|
||||
: AnimatedSize(
|
||||
duration: duration,
|
||||
curve: Motion.curve,
|
||||
alignment: Alignment.topCenter,
|
||||
child: rows,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
|
||||
@@ -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);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user