Skip to content

Commit

Permalink
test: removing widget mid-animation must not leak Ticker
Browse files Browse the repository at this point in the history
  • Loading branch information
Zekfad committed Jan 23, 2025
1 parent daee76b commit 2fa8d3e
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions test/super_sliver_list_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1226,6 +1226,53 @@ void main() async {
expect(detached, 2);
expect(controller.isAttached, false);
});
testWidgets("remove widget mid animation", (tester) async {
final scrollController = ScrollController();

int attached = 0;
int detached = 0;
final controller = ListController(
onAttached: () {
++attached;
},
onDetached: () {
++detached;
},
);
final configuration = SliverListConfiguration.generate(
slivers: 1,
itemsPerSliver: (_) => 20,
itemHeight: (_, __) => 300,
viewportHeight: 500,
addGlobalKey: true,
);
await tester.pumpWidget(_buildSliverList(
configuration,
listController: controller,
preciseLayout: false,
controller: scrollController,
));
await tester.pumpAndSettle();
expect(attached, 1);
expect(detached, 0);
expect(controller.isAttached, isTrue);

controller.animateToItem(
index: () => 10,
scrollController: scrollController,
alignment: 0.5,
duration: (estimatedDistance) => const Duration(milliseconds: 1000),
curve: (estimatedDistance) => Curves.linear,
);

await tester.pump(const Duration(milliseconds: 500));

// will throw if there are any leaked Tickers
await tester.pumpWidget(const SizedBox.shrink());
expect(attached, 1);
expect(detached, 1);
expect(controller.isAttached, false);
});
testWidgets("replace controller", (tester) async {
int attached1 = 0;
int detached1 = 0;
Expand Down

0 comments on commit 2fa8d3e

Please sign in to comment.