collapse method
Collapses the item at the given index, returning true if successfully collapsed.
This method should typically 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> collapse(int index) async {
if (controllers[index] == null || _expanded.length <= _min || !_expanded.contains(index)) {
return false;
}
_expanded.remove(index);
await _controllers[index]!.reverse();
notifyListeners();
return true;
}