fromKeyedWidgetList static method

DiffUtilSliverList<Widget> fromKeyedWidgetList({
  1. required List<Widget> children,
  2. required AnimatedDiffUtilWidgetBuilder insertAnimationBuilder,
  3. required AnimatedDiffUtilWidgetBuilder removeAnimationBuilder,
  4. Duration insertAnimationDuration = const Duration(milliseconds: 300),
  5. Duration removeAnimationDuration = const Duration(milliseconds: 300),
})

Construct a animated list from a list widgets with unique keys.

@param children A List a Widgets with unique keys @param insertAnimationBuilder The animation builder for insert animations @param removeAnimationBuilder The animation builder for insert animations @param insertAnimationDuration The duration of the insert animation @param removeAnimationDuration The duration of the remove animation

Implementation

static DiffUtilSliverList<Widget> fromKeyedWidgetList({
  required List<Widget> children,
  required AnimatedDiffUtilWidgetBuilder insertAnimationBuilder,
  required AnimatedDiffUtilWidgetBuilder removeAnimationBuilder,
  Duration insertAnimationDuration = const Duration(milliseconds: 300),
  Duration removeAnimationDuration = const Duration(milliseconds: 300),
}) {
  //
  if (kDebugMode) {
    final keys = <Key?>{};
    for (final child in children) {
      if (!keys.add(child.key)) {
        throw FlutterError(
            'DiffUtilSliverList.fromKeyedWidgetList called with widgets that do not contain unique keys! '
            'This is an error as changed is this list cannot be animated reliably. Use unique keys or the default constructor. '
            'This duplicate key was ${child.key} in widget $child. '
            'Note: Hot reload is often broken when this happens, better use Hot Restart');
      }
    }
  }
  return DiffUtilSliverList<Widget>(
    items: children,
    builder: (context, widget) => widget,
    insertAnimationBuilder: insertAnimationBuilder,
    removeAnimationBuilder: removeAnimationBuilder,
    insertAnimationDuration: insertAnimationDuration,
    removeAnimationDuration: removeAnimationDuration,
    equalityChecker: (a, b) => a.key == b.key,
  );
}