caduandrade / multi_split_view

Provides horizontal or vertical multiple split view for Flutter.
https://caduandrade.github.io/multi_split_view/
MIT License
129 stars 24 forks source link

How do I save and restore the weights? #27

Closed sgehrman closed 2 years ago

sgehrman commented 2 years ago

onSizeChange gives me two indexes. What do I do with those? I need to get the weights of all the areas so I can save them, but the areas aren't updated until after this is called.

 void _onSizeChange(int childIndex1, int childIndex2) {
    Area tmp = controller.getArea(childIndex1);
    print('$childIndex1 : ${tmp.weight}');   //  <===== old value

    tmp = controller.getArea(childIndex2);
    print('$childIndex2 : ${tmp.weight}');   //  <===== old value
  }

The areas get updated after this call, so I guess I could do a Future.delay and then do the save, but it seems this should be simpler. Am I doing it wrong?

caduandrade commented 2 years ago

Hi @sgehrman!

The childIndex1 and childIndex2 refer to children whose size has been changed. A divider changes the size of two.

You are right about onSizeChange, it is being called before the model is updated. A workaround would be to use Future as you said. But I will change that.

caduandrade commented 2 years ago

I think the ideal will be to change some things. The listener is only notified by dragging the splitter. I think it should be notified in the window resize too. But with that, you will no longer be able to have both indices.

It is also worth remembering that the component does not store the size of each area, but its weights. So in a window resizing, the weights under normal conditions would remain the same and the listener would not be notified. Only when the available space was less than the minimum, then the weight would be forced to change and notify the listener.

caduandrade commented 2 years ago

Renaming OnSizeChange to OnWeightChange to be more coherent.

caduandrade commented 2 years ago

Done. Now you can save using the onWeightChange without Future.delay workaround. To restore you can create a new controller or update it. Example: _controller.areas = [Area(weight: .1)];

sgehrman commented 2 years ago

I got the update. works great now. Thanks!