0

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

grizzzzzy
  • 17
  • 5

1 Answers1

0
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.

rrttrr
  • 1,393
  • 1
  • 6
  • 10