I'm working with draggables and dragtargets in Flutter. I currently have two dragtargets in my project, both respond correctly once I drop a draggable over them. However, once the first drag from draggable1 to dragtarget1 is complete, the second drag brings up an issue: whilst hovering (not dropped) over dragtarget2 with draggable2, the onaccept property is triggered and dragtarget2 is built with the contents of dragtarget1. I don't understand why. I'd be grateful for any help/tips!
I have made a short video with a visual representation of the issue: https://youtu.be/IJa3oZ_7fw0
Here's my code for the dragtarget:
Widget build(BuildContext context) {
bool isSuccessful = false;
int caughtData;
return SafeArea(
child: Column(
children: <Widget>[
Row(
children: <Widget>[
Expanded(
child: Container(
height: 70,
width: 200,
color: Colors.grey.shade600,
child: DragTarget<int>(
builder: (context, List<int> candidateData, rejectedData) {
return isSuccessful
? FlatButton(
color:
chordBrain.chordBank[caughtData].buttoncolor,
child:
Text(chordBrain.chordBank[caughtData].chord),
onPressed: () {
playSound(noteBrain.noteBank[caughtData].note1);
playSound(noteBrain.noteBank[caughtData].note2);
playSound(noteBrain.noteBank[caughtData].note3);
playSound(noteBrain.noteBank[caughtData].note4);
},
)
: Container();
},
onWillAccept: (int data) {
print('$data');
return true;
},
onAccept: (int data) {
print('$data');
isSuccessful = true;
caughtData = data;
},
),
),
),
SizedBox(
width: 8,
),
Expanded(
child: Container(
height: 70,
width: 200,
color: Colors.grey.shade600,
child: DragTarget<int>(
builder: (context, List<int> candidateData, rejectedData) {
return isSuccessful
? FlatButton(
color:
chordBrain.chordBank[caughtData].buttoncolor,
child:
Text(chordBrain.chordBank[caughtData].chord),
onPressed: () {
playSound(noteBrain.noteBank[caughtData].note1);
playSound(noteBrain.noteBank[caughtData].note2);
playSound(noteBrain.noteBank[caughtData].note3);
playSound(noteBrain.noteBank[caughtData].note4);
},
)
: Container();
},
onWillAccept: (int data) {
print('$data');
return true;
},
onAccept: (int data) {
print('$data');
isSuccessful = true;
caughtData = data;
},
),
),
),
],
),