diff --git a/auto_animated_list/lib/src/auto_animated_list.dart b/auto_animated_list/lib/src/auto_animated_list.dart index b104281..fb3fa58 100644 --- a/auto_animated_list/lib/src/auto_animated_list.dart +++ b/auto_animated_list/lib/src/auto_animated_list.dart @@ -1,14 +1,12 @@ -import 'package:flutter/material.dart'; - -import 'package:diffutil_dart/diffutil.dart' as diffutil; - import 'package:auto_animated_list/src/extensions/list_element_at_or_null.dart'; +import 'package:diffutil_dart/diffutil.dart' as diffutil; +import 'package:flutter/material.dart'; /// ListView widget that implicitly animates when `items` changes. class AutoAnimatedList extends StatefulWidget { /// Creates a ListView widget that implicitly animates when `items` changes. const AutoAnimatedList({ - Key? key, + super.key, required this.items, required this.itemBuilder, this.scrollDirection = Axis.vertical, @@ -18,7 +16,8 @@ class AutoAnimatedList extends StatefulWidget { this.physics, this.controller, this.padding, - }) : super(key: key); + this.equalityChecker, + }); /// List of items that the [itemBuilder] should animate widgets for. final List items; @@ -98,6 +97,9 @@ class AutoAnimatedList extends StatefulWidget { /// List items are only built when they're scrolled into view. final Widget Function(BuildContext, T, int, Animation) itemBuilder; + /// Indicates if two items are equal. + final bool Function(T, T)? equalityChecker; + @override State> createState() => _AutoAnimatedListState(); } @@ -139,7 +141,11 @@ class _AutoAnimatedListState extends State> { if (listState == null) return; final newList = widget.items; - final diffResult = diffutil.calculateListDiff(oldList, newList); + final diffResult = diffutil.calculateListDiff( + oldList, + newList, + equalityChecker: widget.equalityChecker, + ); final updates = diffResult.getUpdates(batch: false); if (updates.isEmpty) return; for (final update in updates) {