Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test animation on item update #61

Merged
merged 4 commits into from
Jun 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
branches:
- main
tags:
- '[0-9]+.[0-9]+.[0-9]+*'
- 'v[0-9]+.[0-9]+.[0-9]+*'

jobs:
publish:
Expand All @@ -14,4 +14,4 @@ jobs:
uses: dart-lang/setup-dart/.github/workflows/publish.yml@v1
with:
environment: 'pub.dev'
working-directory: path/to/package/within/repository
# working-directory: path/to/package/within/repository
14 changes: 12 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
# 1.0.5 (Apr 30, 2024)
# v1.0.6

# Changelog

## Bug Fixes
- Add equality check in example app to prevent animation on update of item in list.


# v1.0.5

# Changelog

## Bug Fixes
- Fix `onReorderEnd` callback not being called after reordering is completed.

# 1.0.4 (Apr 14, 2024)
# v1.0.4

# Changelog

Expand All @@ -17,3 +25,5 @@





15 changes: 14 additions & 1 deletion example/lib/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,18 @@ class User {
final int index;

User({required this.name, required this.index});

// To prevent unnecessary animations when updating items in a list, it's essential to correctly implement the == operator and hashCode for your list item class.
// This allows the list to recognize items with the same data as equal, even if they are different instances.

@override
bool operator ==(Object other) {
if (identical(this, other)) return true;
return other is User && other.index == index;
}

@override
int get hashCode => index.hashCode;
}

class HomePage extends StatefulWidget {
Expand All @@ -31,6 +43,7 @@ class _HomePageState extends State<HomePage> {

void insert() {
addedNumber += 1;

setState(() {
list.insert(1, User(name: "User $addedNumber", index: addedNumber));
});
Expand Down Expand Up @@ -160,7 +173,7 @@ class _HomePageState extends State<HomePage> {
scrollDirection: Axis.vertical,
itemBuilder: (BuildContext context, int index) {
return ItemCard(
key: Key(list[index].name),
key: ValueKey(list[index]),
index: list[index].index);
},
sliverGridDelegate:
Expand Down
4 changes: 2 additions & 2 deletions lib/src/builder/motion_animated_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ class MotionBuilderState extends State<MotionBuilder>
}

final Widget child = widget.onReorder != null
? reordreableItemBuilder(context, _itemIndexToIndex(index))
? reorderableItemBuilder(context, _itemIndexToIndex(index))
: widget.itemBuilder(context, _itemIndexToIndex(index));

assert(() {
Expand Down Expand Up @@ -679,7 +679,7 @@ class MotionBuilderState extends State<MotionBuilder>
return SliverChildBuilderDelegate(_itemBuilder, childCount: _itemsCount);
}

Widget reordreableItemBuilder(BuildContext context, int index) {
Widget reorderableItemBuilder(BuildContext context, int index) {
final Widget item = widget.itemBuilder(context, index);
final Widget itemWithSemantics = _wrapWithSemantics(item, index);

Expand Down
3 changes: 2 additions & 1 deletion lib/src/builder/motion_list_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,13 @@ abstract class MotionListBaseState<
void initState() {
super.initState();
oldList = List.from(widget.items);

addEffects(enterTransition, _enterAnimations, enter: true);
addEffects(exitTransition, _exitAnimations, enter: false);
}

@override
void didUpdateWidget(covariant B oldWidget) {
super.didUpdateWidget(oldWidget);
final newList = widget.items;
if (!listEquals(oldWidget.enterTransition, enterTransition)) {
_enterAnimations = [];
Expand All @@ -145,6 +145,7 @@ abstract class MotionListBaseState<
}
calculateDiff(oldList, newList);
oldList = List.from(newList);
super.didUpdateWidget(oldWidget);
}

void addEffects(List<AnimationEffect> effects, List<EffectEntry> enteries,
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: animated_reorderable_list
description: A Flutter Reorderable Animated List with simple implementation and smooth transition.
version: 1.0.5
version: 1.0.6
repository: https://github.com/canopas/animated_reorderable_list

environment:
Expand Down
Loading