form_bloc icon indicating copy to clipboard operation
form_bloc copied to clipboard

Inconsistency with `ListFieldBloc#updateFieldBlocs`

Open Zekfad opened this issue 1 year ago • 1 comments

I've tried to use ReorderableListView with ListFieldBloc and found following inconsistency:

final shapes = ListFieldBloc<ShapePropertiesBloc, void>();

This one produces incorrect results inconsistently

  void reorderShape(int oldIndex, int newIndex) {
    final blocs = shapes.state.fieldBlocs;
    final shapeBloc = blocs.removeAt(oldIndex);
    blocs.insert(
      oldIndex < newIndex
        ? newIndex - 1
        : newIndex,
      shapeBloc,
    );
    shapes.updateFieldBlocs(blocs);
  }

This method produces correct results, but creates a junk frames due to double emit.

  void reorderShape(int oldIndex, int newIndex) {
     shapes
      ..removeFieldBlocAt(oldIndex)
      ..insertFieldBloc(
        shapeBloc,
        oldIndex < newIndex
          ? newIndex - 1
          : newIndex,
      );
  }

I suspect issue is with order of FormBlocUtils calls, because they are different if I use patch method.

Zekfad avatar Feb 02 '24 00:02 Zekfad

https://github.com/GiancarloCode/form_bloc/pull/312#issuecomment-1164240179

vasilich6107 avatar Jun 24 '24 21:06 vasilich6107