findIndexByKey method

  1. @override
int? findIndexByKey(
  1. Key key
)
override

Find index of child element with associated key.

This will be called during performRebuild in SliverMultiBoxAdaptorElement to check if a child has moved to a different position. It should return the index of the child element with associated key, null if not found.

If not provided, a child widget may not map to its existing RenderObject when the order of children returned from the children builder changes. This may result in state-loss.

Implementation

@override
int? findIndexByKey(Key key) {
  final Key childKey;
  if (key is _SaltedValueKey) {
    final _SaltedValueKey saltedValueKey = key;
    childKey = saltedValueKey.value;
  } else {
    childKey = key;
  }
  return _findChildIndex(childKey);
}