diffutil_dart 0.1.0+1

diffutil.dart #

Pub Package Coverage

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

0.1.0+1 #

  • more tests

0.1.0 #

  • Fix bug in move detection
  • Tighten up privacy of instance variables that were unnecessarily public
  • add tests

0.0.7 #

Fix lint errors

0.0.6 #

Fix missing exports

0.0.5 #

Add support for custom list-like types

0.0.4 #

Add example

0.0.3 #

Update Package description

0.0.2 #

Dokumentation Fixes

0.0.1 - Initial Release #


import 'package:diffutil_dart/diffutil.dart' as diffutil;

void main() {
  final oldList = [1, 2, 3];
  final newList = [2, 3, 4];

  print("difference between $oldList and $newList, with move detection:");

  final listDiff = diffutil.calculateListDiff(oldList, newList);


  final oldList2 = [1, 2, 3];
  final newList2 = [1, 3, 2];


  print("difference between $oldList and $newList, without move detection:");

  final listDiff2 = diffutil.calculateListDiff(oldList2, newList2, detectMoves: false);



  print("difference between $oldList and $newList, with move detection:");

  final listDiff3 = diffutil.calculateListDiff(oldList2, newList2, detectMoves: true);



class MyListCallback implements diffutil.ListUpdateCallback {
  void onChanged(int position, int count, Object payload) {
    print("$count item(s) on position $position changed!");

  void onInserted(int position, int count) {
    print("$count item(s) on position $position have been inserted!");

  void onMoved(int fromPosition, int toPosition) {
    print("item on position $fromPosition moved to $toPosition!");

  void onRemoved(int position, int count) {
    print("$count item(s) on position have been removed!");

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  diffutil_dart: ^0.1.0+1

2. Install it

You can install packages from the command line:

with pub:

$ pub get

with Flutter:

$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:diffutil_dart/diffutil.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Feb 10, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.5

Health suggestions

Format lib/src/diff_delegate.dart.

Run dartfmt to format lib/src/diff_delegate.dart.

Format lib/src/diffutil_impl.dart.

Run dartfmt to format lib/src/diffutil_impl.dart.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.6.0 <3.0.0
Dev dependencies
mockito ^4.1.1
test ^1.12.0
test_coverage ^0.4.1