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

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.