Closed isenbj closed 1 year ago
Hi @isenbj
Thanks for opening the issue. I can add the data
as parameter, but only for the prerelease of 5.0.0
.
Can you explain me, how the data is used or when do you want to access the data?
A Draggable class in flutter has a data class that will hold any data I desire.
In my case, I have a grid of images and each image has some metadata I allow a user to customize. I want to allow a user to drag these grid elements to an off-grid widget (such as a folder) and have that metadata available. This will allow me to execute some code that actually adds the image to that folder. Currently if I add a DragTarget anywhere in the app, the data for the widget is not passed through and is null.
I branched your repo and put together a crude example of what I mean to get the data through here.
Since you allow any child type in the gridview for each element, you may have to build in an optional child type that allows this data to be passed through per child.
I will add this parameter just by passing it to the widget, I will add it this week in the version 5.0.0-dev.7
@isenbj
Will you be some to make it unique per grid item this way?
Oh now I know what you mean, yeah it has to be unique per item, that makes it more complicated, I will think about a solution @isenbj
My idea is that you can optionally wrap a widget around your child that has the data
property. If your widget has this, I could extract the info and use it for Draggable
. @isenbj
Yes, see the shared fork of the repo I shared above. I am doing this locally and it is working.
On Mon, Jun 19, 2023 at 12:27 AM karvulf @.***> wrote:
My idea is that you can optionally wrap a widget around your child that has the data property. If your widget has this, I could extract the info and use it for Draggable. @isenbj https://github.com/isenbj
— Reply to this email directly, view it on GitHub https://github.com/karvulf/flutter-reorderable-grid-view/issues/77#issuecomment-1596528778, or unsubscribe https://github.com/notifications/unsubscribe-auth/AL322JUZSR4HRNTQERMMESTXL7PL5ANCNFSM6AAAAAAZJZZYFA . You are receiving this because you were mentioned.Message ID: @.***>
Yes I saw the repo.
My concern about this change is, that it would be a breaking change changing the type. It has also to be changed for the factory .builder
. That is the reason I prefer using an extra widget. @isenbj
Yes, so another option would be add a custom class with a data property, and when you create the Draggable and LongPressDraggable widgets, you can type check the child to see if the data exists. This would require the fewest changes I think.
On Mon, Jun 19, 2023 at 12:40 AM karvulf @.***> wrote:
Yes I saw the repo. My concern about this change is, that it would be a breaking change changing the type. It has also to be changed for the factory .builder. That is the reason I prefer using an extra widget. @isenbj https://github.com/isenbj
— Reply to this email directly, view it on GitHub https://github.com/karvulf/flutter-reorderable-grid-view/issues/77#issuecomment-1596536779, or unsubscribe https://github.com/notifications/unsubscribe-auth/AL322JU6FI3QMQCW2KTQ2PLXL7Q3TANCNFSM6AAAAAAZJZZYFA . You are receiving this because you were mentioned.Message ID: @.***>
That sounds good @isenbj
Can you check if this change does that what you wished for? @isenbj
You can add the following to your pubspec.yaml
:
flutter_reorderable_grid_view:
git:
url: https://github.com/karvulf/flutter-reorderable-grid-view.git
ref: 7f06cb0c954a2353029ee9b79f22a208dde27fd7
and you just have to add to every child:
return CustomDraggable(
key: Key(children[index].toString()),
data: index,
child: ...
Yes this passes the data as I wanted to a drag target.
Note: I am not sure if you are working on other changes, but this commit broke other things in my code. ex.
That's all I've noticed so far, so I can't use this commit yet with those breaking changes perhaps related to other changes.
Hmm that sounds weird. Did you use version 5.0.0-dev.6
before? And can you give the code that has this behavior? @isenbj
The issues you describe I couldn't reproduce them with the example app. Can you show me your code? @isenbj I will merge this as it is. Another thing I recognized are some performance issues after a while using drag and drop. I will fix that in another PR.
I added the feature to the branch for the release 5.0.0
. Soon I will update the pre version to 5.0.0-dev.7
@isenbj
I've been off for a few days, checking again now to see if I can reproduce issues. I will use commit: aaa8d9b0a6c5315bb6cdc4582a78d50ad406f7a3
This looks good to me now, and I cannot reproduce the issues. Nice job!
How do I use the onReorder function now? I am confused since it has changed.
The reorder function now gives you a function that reorders for you the list. You can see it in the example app. @isenbj
void _handleReorder(ReorderedListFunction reorderedListFunction) {
setState(() {
children = reorderedListFunction(children) as List<int>;
});
}
I'd like to be able to drag elements from the grid onto DragTargets in my app. Currently null is passed through as the data though.
see draggables I would like data added to here: https://github.com/karvulf/flutter-reorderable-grid-view/blob/master/lib/widgets/animated/reorderable_draggable.dart#L150