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

no event occurs when the divider is dragging. #45

Closed SooChang-Lee closed 2 months ago

SooChang-Lee commented 1 year ago

Thanks for the nice plugin.

I want to receive an event when the Divider is dragging.

I added a listener using MultiSplitViewController.addListener(), but no event occurs when the Divider is dragging.

class _DesktopContainerWidgetState extends State<DesktopContainerWidget> {
   final MultiSplitViewController multiSplitViewController = MultiSplitViewController(areas: [
     Area(size: 220, minimalSize: 140),
     Area(minimalSize: 140)
   ]);

   double _masterWidgetWidth = 0;

   @override
   void initState() {
     super.initState();

     multiSplitViewController. addListener(() {
       setState(() {
         _masterWidgetWidth = multiSplitViewController.getArea(0).size ?? 0;
       });
     });
   }

  @override
  Widget build(BuildContext context) {
    final double dividerThickness = context.isDesktopPlatform ? 4 : 24;

    return Scaffold(
      body: MultiSplitViewTheme(
        data: MultiSplitViewThemeData(dividerThickness: dividerThickness),
        child: MultiSplitView(
          dividerBuilder: (axis, index, resizable, dragging, highlighted, themeData) {
            return Container(
              color: dragging ? Colors.grey[300] : Colors.grey[100],
              child: Icon(
                Icons.drag_indicator,
                color: highlighted ? Colors.grey[600] : Colors.grey[400],
              ),
            );
          },
          controller: multiSplitViewController,
          children: const [
            FolderListWidget(),
            FileListWidget(),
          ],
        ),
      ),
    );
  }
}
SooChang-Lee commented 1 year ago

Additionally in onWeightChange() _multiSplitViewController.getArea(0).size always returns null. However, _multiSplitViewController.getArea(0).weight returns a normal value.(ex 0.206846468)

caduandrade commented 1 year ago

Hi @SooChang-Lee!

You shouldn't use the controller's addListener to get notified on changing dividers. This listener only notifies you of areas being added or removed.

So you should use onWeightChange ok? As the name of the event says, it informs the weight change. The size parameter is only used to define the initial size given the size of the container component. The MultiSplitViewController keeps the data always in weight. If it were in size (pixels), we would have problems resizing the window or even adding a new area ok?

Perhaps the size parameter should be renamed to initialSize.

SooChang-Lee commented 1 year ago

Thanks for the reply.

I want to be notified in real time when the size of the panel changes. When the size of the panel changes, it is used to adjust the size of other widgets.

Is there any way to be notified in real time whenever the size of the panel changes?

caduandrade commented 3 months ago

Will be resolved by #54

caduandrade commented 2 months ago

Done (version 3.0.0)

    MultiSplitView multiSplitView = MultiSplitView(initialAreas: [
      Area(widget: Draft.blue()),
      Area(widget: Draft.yellow()),
      Area(widget: Draft.green())
    ], onDividerDragUpdate: (index) => print('divider index: $index'));
Uche01 commented 1 month ago

Done (version 3.0.0)

    MultiSplitView multiSplitView = MultiSplitView(initialAreas: [
      Area(widget: Draft.blue()),
      Area(widget: Draft.yellow()),
      Area(widget: Draft.green())
    ], onDividerDragUpdate: (index) => print('divider index: $index'));

Just updated to version 3.0.0 because of the onDividerDragUpdate. However, there are breaking changes: No more Area.weight parameter? What is it's equivalent in this new version?. Also No MultiSplitView.children property, one would have to use initialAreas instead. This changes needs to be documented

caduandrade commented 1 month ago

Hi @Uche01

https://pub.dev/packages/multi_split_view

Every package on pub.dev has the CHANGELOG session. See the example demo link.