Reputation: 2056
I’ve been looking for a way to permanently move selected items to the top of a ListView in flutter.
This would work by pressing an iconbutton
, next to a ListView
element, and having this element move to the top upon a refresh
.
If possible, I’d like the icon button to become enabled
(ie glow / light up) when it’s enabled, and disabled
(greyed out, but still press-able) when disabled.
I wouldn’t be able to fit in all my code in this question, so all that along with _getListItemUi
are available at: https://github.com/Jak3-02/myproject2
This is what my current ListView looks like:
Widget _cryptoWidget() {
return new Container(
child: new Column(
children: <Widget>[
new Flexible(
child: new ListView.builder(
itemCount: _currencies.length,
itemBuilder: (BuildContext context, int index) {
final int i = index ~/ 2;
final Crypto currency = _currencies[i];
final MaterialColor color = _colors[i % _colors.length];
if (index.isOdd) {
return new Divider();
}
return _getListItemUi(currency, color);
},
),
),
],
)
);
}
Thank you, all ideas are appreciated. :)
Upvotes: 4
Views: 3209
Reputation: 46
This sounds a lot like a class project, so I'm going to point you in the right direction to figure this out for yourself.
Notice the Item Builder in your code. It reads the _currencies list and builds the corresponding widgets. What would happen if you rearranged the items in _currencies and ran this code again?
How would you get the _cryptoWidget to redraw when its _currencies list changes? Would you use a Stateful widget or a Stateless one? Which of these redraws itself when its data changes?
You want a clickable icon that can look different when it's enabled and disabled. Have you looked in the Widget Catalog?
With these notes, you should be able to solve this pretty easily.
Upvotes: 3