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

[Feacture] pass the MultiSplitViewController on onDividerDragUpdate #71

Open rodolfogoulart opened 2 weeks ago

rodolfogoulart commented 2 weeks ago

Can you add to onDividerDragUpdate the controller of the MultiSplitView?

I was using the previous version of the MultiSplitView, and used the onWeightChange to save the weight of the area, so the user when open the app will have the area started on their respective size as he changed before.

to replicate this on this new version its been hard, a lot of workaround to do.

if we can have like that

onDividerDragUpdate

onDividerDragUpdate(index, controller){
}

to do that need to change this

typedef OnDividerDragUpdate = void Function(int index, MultiSplitViewController controller);
void _onDragUpdate(
      DragUpdateDetails detail, int index, ControllerHelper controllerHelper) {
    if (_draggingDivider == null) {
      return;
    }

    final Offset offset = _offset(context, detail.globalPosition);
    final double position;
    if (widget.axis == Axis.horizontal) {
      if (detail.delta.dx == 0) {
        return;
      }
      position = offset.dx;
    } else {
      if (detail.delta.dy == 0) {
        return;
      }
      position = offset.dy;
    }

    final double newDividerStart = position - _draggingDivider!.initialInnerPos;
    final double lastDividerStart = _layoutConstraints.dividerStartOf(
        index: index,
        controller: _controller,
        antiAliasingWorkaround: widget.antiAliasingWorkaround);

    DividerUtil.move(
        controller: _controller,
        layoutConstraints: _layoutConstraints,
        dividerIndex: index,
        pixels: newDividerStart - lastDividerStart,
        pushDividers: widget.pushDividers);

    controllerHelper.notifyListeners();
    if (widget.onDividerDragUpdate != null) {
      //TODO: Change here
      Future.delayed(Duration.zero, () => widget.onDividerDragUpdate!(index, _controller));
    }
  }

this way, i can have acess to the area itself,

caduandrade commented 2 weeks ago

Hi @rodolfogoulart!

Of course, but just curious, are you using MultiSplitView inside a StatelessWidget? Is that why you don't have the reference for the MultiSplitViewController?

caduandrade commented 2 weeks ago

I asked because with the state you already have the reference to the controller:

class MultiSplitViewExampleState extends State<MultiSplitViewExample> {
  final MultiSplitViewController _controller = MultiSplitViewController();

  @override
  void initState() {
    super.initState();
    _controller.areas = [
      Area(builder: (c, a) => const MyStatefulWidget()),
      Area(builder: (c, a) => const MyStatefulWidget())
    ];
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(title: const Text('Multi Split View Example')),
        body: MultiSplitView(
            controller: _controller,
            onDividerDragUpdate: _onDividerDragUpdate));
  }

  void _onDividerDragUpdate(int index) {
    // _controller.areas
  }
}
rodolfogoulart commented 2 weeks ago

Obrigado @caduandrade . Com esta nova versão eu estava com problemas para entender as modificações que precisava fazer aqui. Mas fiz as modificações criando o controller do MultiSplitViewController no initState e usando o builder: (BuildContext context, Area area) do MultiSplitView, no começo não tinha entendido aquele builder não kkkkk

mas ficou bacana, bom que a nova versão eliminou um bug que estava sofrendo aqui, na antiga versão.

Outra coisa, nesta nova versão, se puder mesmo disponibilizar o controller no onDragUpdate e nos outros métodos que somente esta passando o index, iria ajudar aqueles que por algum motivo estejam usando o initialAreas, porque quando usado sem o controller, os métodos (onDividerDragUpdate, onDividerDoubleTap, onDividerTap) ficam meio sem sentido, só sabendo o index, sem as funções do controller interno. mas fica mais para sugestão do que para necessidade rs