diffutil_dart 0.0.6 copy "diffutil_dart: ^0.0.6" to clipboard
diffutil_dart: ^0.0.6 copied to clipboard

outdated

Calculate the difference between two lists. Used for implicitly animating Flutter lists without having to maintain a StatefulWidget.

diffutil.dart #

Calculate the difference between two lists.

Heavily inspired bei Android's DiffUtil class, the code was adopted for Dart.

Uses Myers algorithm internally.

Usage #

Calculating diffs: #

Simple usage:

final diffResult = calculateListDiff([1, 2 ,3], [1, 3, 4]);

Custom equality:

final diffResult = calculateListDiff(oldList, newList, (o1, o2) => o1.id == o2.id);

If you don't want to use plain old Dart lists (for example if you're using built_value or kt.dart), and don't want to convert your custom list to standard lists, you can use the calculateDiff function and implement your own DiffDelegate easily.

Or use calculateCustomListDiff and CustomListDiffDelegate.

Using the result: #

Implement ListUpdateCallback and call diffResult.dispatchUpdatesTo(myCallback);

Performance metrics: #

Same as Android's DiffUtil:

  • O(N) space
  • O(N + D^2) time performance where D is the length of the edit script.
  • additional O(N^2) time where N is the total number of added and removed items if move detection is enabled
64
likes
0
pub points
96%
popularity

Publisher

verified publisherlittlebat.dev

Calculate the difference between two lists. Used for implicitly animating Flutter lists without having to maintain a StatefulWidget.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

More

Packages that depend on diffutil_dart