Closed vin-fandemand closed 4 years ago
As per Advanced Usage:
You can use the setter
DragSelectGridViewController.selection
to directly change the selection (I'm not quite sure why you'd need this, but I don't ask questions).
Here's an example:
Is this helpful?
Yes. Thanks a lot.
actually, this is not exactly initialization. When you set this, you would notify listeners. Now we usually initialize in the beginning and hence setting state then wouldn't be ideal. The example you have given is useful when you want to update the selection later.
So this is the use case. We have a grid of stuff. And we need to show the ones that have already been selected as selected and don't want to select them again. Hence we need a way to initialize it.
can you please reopen this issue if possible ?
Now we usually initialize in the beginning and hence setting state then wouldn't be ideal.
I agree. There's probably a way to work around that, though. I'll take a look later.
There are some ways to implement this feature, but I need to check how Flutter and other libraries manage to get this working, in order to follow their pattern.
In the meanwhile, you may use after_layout
to change the selection after the first frame has been displayed:
class _MyAppState extends State<MyApp> with AfterLayoutMixin<MyApp> {
final controller = DragSelectGridViewController();
@override
void initState() {
super.initState();
controller.addListener(scheduleRebuild);
}
@override
void dispose() {
controller.removeListener(scheduleRebuild);
super.dispose();
}
@override
void afterFirstLayout(BuildContext context) {
controller.selection = const Selection({1, 2, 3});
}
...
}
@vin-fandemand Now, specifying a Selection
in DragSelectGridViewController
should work for you :)
@vin-fandemand Now, specifying a
Selection
inDragSelectGridViewController
should work for you :)
Thanks, mate, I will test and let me know
Is there a way to initialize the selections? Like pass in the indexes to the controller?