I make draggable in in my app
where I want the data from draggable to pass to dragTarget
and that data put in List of userInput
but as I can see the list is not growing when I try to print it.
what did I do wrong?
Widget _generateOpaque(int index) {
return DragTarget<Box>(
builder: (BuildContext context, List<dynamic> accepted,
List<dynamic> rejected) {
return opaqueBoxes.elementAt(index).filled
? _filledBox(index)
: _opaqueBox(index);
},
onWillAccept: (data) {
return true;
},
onAccept: (data) {
setState(() {
List<Box> userInput = [];
userInput.add(data);
print(userInput.length);
});
},
);
}
I want data to put in the list
CodePudding user response:
List<Box> userInput = [];
This should be outside _generateOpaque(int index)
.
In your code, each time onAccept()
is called, new empty list List<Box> userInput = [];
is being created.