Skip to content

Add .separated constructor to ReorderableListView #168834

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 32 commits into
base: master
Choose a base branch
from

Conversation

Fintasys
Copy link

@Fintasys Fintasys commented May 14, 2025

This PR introduces a .separated constructor to the ReorderableListView widget. The .separated constructor allows developers to define custom separators between the list items without the need to manually modify their list or create custom widgets. This API enhancement improves the overall usability and flexibility of ReorderableListView.

Key Changes:

  • Added a new .separated constructor to ReorderableListView.
  • Included appropriate documentation for the new constructor with usage examples.
  • Updated the relevant tests to verify the behavior of .separated functionality.
  • Ensured backward compatibility for existing constructors.

This new feature addresses the requests in issue #76706.

Pre-launch Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

Video

separated_example.mp4

@github-actions github-actions bot added framework flutter/packages/flutter repository. See also f: labels. f: material design flutter/packages/flutter/material repository. d: api docs Issues with https://api.flutter.dev/ d: examples Sample code and demos labels May 14, 2025
@Fintasys Fintasys changed the title Add separated constructor to reorderable list Add .separated constructor to ReorderableListView May 14, 2025
@Fintasys Fintasys marked this pull request as ready for review May 15, 2025 04:29
@dkwingsmt dkwingsmt requested a review from victorsanni May 21, 2025 18:11
@victorsanni victorsanni requested a review from bleroux May 22, 2025 23:50
@Fintasys
Copy link
Author

@victorsanni Thanks for the detailed review ! I tried to address all of your concerns, please have another look 🙇

Copy link
Contributor

@victorsanni victorsanni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for responding! Can you also attach videos/screenshots to the PR description comparing before/after? This will make the PR easier to review.

The example and tests are also really nice. For now, can you attach the example code to the PR description, and add the example/example test in a subsequent PR? The leaner the PR, the easier it is to review.

Thanks once again.

throw FlutterError('Every item of ReorderableListView must have a key.');
// Separators built by widget.itemBuilder (when widget.separatorBuilder is non-null and index is odd)
// might not have keys or might have non-GlobalKeys.
// This assertion should only apply to actual reorderable items.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this tested?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added tests for these use cases 👍

await drag.up();
}

testWidgets('Reorder list item with separators', (WidgetTester tester) async {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is testing the reorderable behavior? Is there a test like this in reorderable_list_test.dart?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it's testing the reorderable behavior, similar to the other constructors.
There is no behavior test in reorderable_list_test.dart which is also aligned with the other constructors.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Example tests should only confirm that visually, all intended widgets are displayed. All behavior tests should be in the actual widget test file. There may be places in the codebase where that has slipped through the cracks but that is the original purpose.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay I moved the test and created simple visual regression test for the example 👍

@@ -0,0 +1,65 @@
// Copyright 2014 The Flutter Authors. All rights reserved.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this example generate the video in the PR description? In the video, the way the separators move with the tiles looks off. For example, a separator appears at the top if the first tile is reordered. Also, the separators appear above the tiles while reordering. Can the example be updated to fix these and others?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree the behavior looks a bit off with the default Divider. In my own app the Divider appearance is different and doesn't look & feel off.
But in order to improve this behavior I would need to make changes to the underlying SliverReorderableList and e.g. expose a callback that allows the SliverReorderableList to understand between draggable and non-draggable widgets. That would also reintroduce childCount and the helper function that we just removed.
I'm worried that this goes beyond of the current scope of this PR and might be better addressed in a separate PR?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it possible to expand the example to use another ReorderableListView property to achieve this? For example, onReorder or proxyDecorator.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, unfortunately I don't think so.

  • onReorder: This callback is invoked after the item is dropped and is used to update the data model. It doesn't affect the visual behavior during the drag.

  • proxyDecorator: This callback is to customize the appearance of the item being dragged (the proxy). It does not control the behavior or rendering of the other items or the separators in the list.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
d: api docs Issues with https://api.flutter.dev/ d: examples Sample code and demos f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants