'How to create flexible widget as a child of the Reorderable Column/ListView in Flutter?
I need to create a list of player cards with a fixed number inside a flexible widget. If I use a simple column widget, it works well.
class _PlayerListState extends State<PlayerList> {
@override
Widget build(BuildContext contextt) {
//inside Flexible widget
return Column(
children: <Widget>[
for (int index = 0; index < widget.players.length; index++) //widget.players.length
Expanded(
child: _playerCards(index)),
],
);
}
_playerCards widget:
Widget _playerCards(int index) => Dismissible(
key: Key(widget.players[index].name),
child: Expanded(
child: Padding(
padding: const EdgeInsets.only(bottom: stdHorizontalOffset / 2),
child: Container(
padding: const EdgeInsets.only(right: stdEdgeOffset * 0.7),
child: ...
)
But if i use ReorderableListView or ReorderableColumn, cards have size of their inside objects (image imho)
class _PlayerListState extends State<PlayerList> {
@override
Widget build(BuildContext contextt) {
return ReorderableListView(
children: <Widget>[
for (int index = 0; index < widget.players.length; index++)
Expanded(
key: ValueKey(index),
child: _playerCards(index)),
],
onReorder:(int oldIndex, int newIndex){
setState((){
if (oldIndex < newIndex) {
newIndex -=1;
}
final int item = widget.players.removeAt(oldIndex);
widget.players.insert(newIndex,item);
});
widget.callbackFunction();
}
);
}
So, how can i make flexible containers like an object of ReorderableListView or some other ways to make reordering in my case? I also tried to make simple ListView inside flexible widget but without success.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
