Skip to content

Commit 2fa8d3e

Browse files
committed
test: removing widget mid-animation must not leak Ticker
1 parent daee76b commit 2fa8d3e

1 file changed

Lines changed: 47 additions & 0 deletions

File tree

test/super_sliver_list_test.dart

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1226,6 +1226,53 @@ void main() async {
12261226
expect(detached, 2);
12271227
expect(controller.isAttached, false);
12281228
});
1229+
testWidgets("remove widget mid animation", (tester) async {
1230+
final scrollController = ScrollController();
1231+
1232+
int attached = 0;
1233+
int detached = 0;
1234+
final controller = ListController(
1235+
onAttached: () {
1236+
++attached;
1237+
},
1238+
onDetached: () {
1239+
++detached;
1240+
},
1241+
);
1242+
final configuration = SliverListConfiguration.generate(
1243+
slivers: 1,
1244+
itemsPerSliver: (_) => 20,
1245+
itemHeight: (_, __) => 300,
1246+
viewportHeight: 500,
1247+
addGlobalKey: true,
1248+
);
1249+
await tester.pumpWidget(_buildSliverList(
1250+
configuration,
1251+
listController: controller,
1252+
preciseLayout: false,
1253+
controller: scrollController,
1254+
));
1255+
await tester.pumpAndSettle();
1256+
expect(attached, 1);
1257+
expect(detached, 0);
1258+
expect(controller.isAttached, isTrue);
1259+
1260+
controller.animateToItem(
1261+
index: () => 10,
1262+
scrollController: scrollController,
1263+
alignment: 0.5,
1264+
duration: (estimatedDistance) => const Duration(milliseconds: 1000),
1265+
curve: (estimatedDistance) => Curves.linear,
1266+
);
1267+
1268+
await tester.pump(const Duration(milliseconds: 500));
1269+
1270+
// will throw if there are any leaked Tickers
1271+
await tester.pumpWidget(const SizedBox.shrink());
1272+
expect(attached, 1);
1273+
expect(detached, 1);
1274+
expect(controller.isAttached, false);
1275+
});
12291276
testWidgets("replace controller", (tester) async {
12301277
int attached1 = 0;
12311278
int detached1 = 0;

0 commit comments

Comments
 (0)