drag_select_grid_view icon indicating copy to clipboard operation
drag_select_grid_view copied to clipboard

How to get the select parameter outside the Gridview ?

Open Loopex2019 opened this issue 4 years ago • 6 comments

Hi . I am using the SelectableItem , that was created in the example code . It needs the selected parameter which needs to be passed from the itembuilder function :

itemBuilder: (BuildContext context, int index, bool selected) {         
           return _mediaList[index];
   }),

The Problem is as you can see that i am storing the SelectableItem in a mediaList variable. So i want to find a way to get the selected parameter to get passed to the SelectableItem.

Loopex2019 avatar Apr 21 '20 09:04 Loopex2019

@hugocbpassos do you have any idea about how to solve it ?

Loopex2019 avatar Apr 21 '20 11:04 Loopex2019

Since you want _SelectableItemState.didUpdateWidget() to be called, the only way to do so is by creating a new widget, so you are not supposed to store a SelectableItem.

By the way, why are you doing it?

ghost avatar Apr 21 '20 14:04 ghost

I am using the Photo manager pacakge to retrieve media from storage .And for some other reasons i need to call SelectableItem in another function.

Loopex2019 avatar Apr 21 '20 15:04 Loopex2019

Since you want _SelectableItemState.didUpdateWidget() to be called, the only way to do so is by creating a new widget, so you are not supposed to store a SelectableItem.

By the way, why are you doing it?

I didn't understand what you meant exactly .

Loopex2019 avatar Apr 21 '20 15:04 Loopex2019

I didn't understand what you meant exactly .

The whole logic of the SelectableItem relies on _SelectableItemState.didUpdateWidget(). The only way to get this method fired is by creating a new SelectableItem every time selected changes, so you can't store it.

I am using the Photo manager pacakge to retrieve media from storage .And for some other reasons i need to call SelectableItem in another function.

I'm pretty sure there are better ways to solve this. Please open a question at Stack Overflow with the details, so I (or somebody else) might be able to help you.

ghost avatar Apr 21 '20 15:04 ghost

I created a custom class called ItemData , like : ``` class ItemData { final int index; final bool selected; ItemData({this.index, this.selected = false}); }

The i passed the index and the selected parameters to the ItemData object like that :

itemBuilder: (BuildContext context, int index, bool selected) { _itemData = ItemData(index: index, selected: selected); return _mediaList[_itemData.index]; },

The index worked fine but the selcted value doesn't work : like : `SelectableItem(
selected: _itemData.selected,
)`
Is that custom class a correct step or not . And if not is there a way to access the selected boolean through the controller ? 

Loopex2019 avatar Apr 21 '20 15:04 Loopex2019