Skip to content
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

How to get the select parameter outside the Gridview ? #10

Open
Loopex2019 opened this issue Apr 21, 2020 · 6 comments
Open

How to get the select parameter outside the Gridview ? #10

Loopex2019 opened this issue Apr 21, 2020 · 6 comments
Labels
question Further information is requested

Comments

@Loopex2019
Copy link

Loopex2019 commented Apr 21, 2020

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
Copy link
Author

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

@ghost
Copy link

ghost commented Apr 21, 2020

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?

@Loopex2019
Copy link
Author

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
Copy link
Author

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 .

@ghost
Copy link

ghost commented Apr 21, 2020

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.

@Loopex2019
Copy link
Author

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 ? 

@hcbpassos hcbpassos added the question Further information is requested label Sep 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants