Unverified Commit 9b86a485 authored by Jessica Pereira's avatar Jessica Pereira Committed by GitHub

Fix gets removedItem instead of its index (#119638)

* fix: gets removedItem instead of its index
add: sliver_animated_list.0_test.dart

* fix: sliver_animated_list.0_test.dart

* fix: pr comments

* fix test import
Co-authored-by: 's avatarTaha Tesser <tessertaha@gmail.com>

---------
Co-authored-by: 's avatarTaha Tesser <tessertaha@gmail.com>
parent d875899a
......@@ -135,8 +135,8 @@ class _SliverAnimatedListSampleState extends State<SliverAnimatedListSample> {
}
}
typedef RemovedItemBuilder = Widget Function(
int item, BuildContext context, Animation<double> animation);
typedef RemovedItemBuilder<E> = Widget Function(
E item, BuildContext context, Animation<double> animation);
// Keeps a Dart [List] in sync with an [AnimatedList].
//
......@@ -155,7 +155,7 @@ class ListModel<E> {
}) : _items = List<E>.from(initialItems ?? <E>[]);
final GlobalKey<SliverAnimatedListState> listKey;
final RemovedItemBuilder removedItemBuilder;
final RemovedItemBuilder<E> removedItemBuilder;
final List<E> _items;
SliverAnimatedListState get _animatedList => listKey.currentState!;
......@@ -171,7 +171,7 @@ class ListModel<E> {
_animatedList.removeItem(
index,
(BuildContext context, Animation<double> animation) =>
removedItemBuilder(index, context, animation),
removedItemBuilder(removedItem, context, animation),
);
}
return removedItem;
......@@ -197,7 +197,7 @@ class CardItem extends StatelessWidget {
this.selected = false,
required this.animation,
required this.item,
}) : assert(item >= 0);
}) : assert(item >= 0);
final Animation<double> animation;
final VoidCallback? onTap;
......
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:flutter_api_samples/widgets/animated_list/sliver_animated_list.0.dart' as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets(
'Items can be selected, added, and removed from SliverAnimatedList',
(WidgetTester tester) async {
await tester.pumpWidget(const example.SliverAnimatedListSample());
expect(find.text('Item 0'), findsOneWidget);
expect(find.text('Item 1'), findsOneWidget);
expect(find.text('Item 2'), findsOneWidget);
// Add an item at the end of the list
await tester.tap(find.byIcon(Icons.add_circle));
await tester.pumpAndSettle();
expect(find.text('Item 3'), findsOneWidget);
// Select Item 1.
await tester.tap(find.text('Item 1'));
await tester.pumpAndSettle();
// Add item at the top of the list
await tester.tap(find.byIcon(Icons.add_circle));
await tester.pumpAndSettle();
expect(find.text('Item 4'), findsOneWidget);
// Remove selected item.
await tester.tap(find.byIcon(Icons.remove_circle));
// Item animation is not completed.
await tester.pump();
expect(find.text('Item 1'), findsOneWidget);
// When the animation completes, Item 1 disappears.
await tester.pumpAndSettle();
expect(find.text('Item 1'), findsNothing);
},
);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment