toggle method
Toggles the item at the given index, expanding it if it is collapsed and vice versa.
This method should not be called while the widget tree is being rebuilt.
Testing
To avoid timeouts in widget tests, always wrap the returned Future in unawaited.
testWidgets('shows', (tester) async {
await tester.pumpWidget(...);
unawaited(controller.show());
await tester.pumpAndSettle();
});
Implementation
Future<bool> toggle(int index) async => switch (_controllers[index]?.status) {
null => false,
final status when status.isForwardOrCompleted => await collapse(index),
_ => await expand(index),
};