Trying to automate Drag and drop for testing. Element is of type Draggable<Student>.
Tried drag() with longPress(). Tried drag with Offset and also tried moveTo() from TestGesture. But still unable to drag the element to the box.
//await _tester.longPress(_finder);
//await _tester.drag(_finder, offset);
final Offset firstLocation = _tester.getCenter(_finder);
await _tester.longPress(_finder);
final TestGesture gesture =
await _tester.startGesture(firstLocation, pointer: 5);
await _tester.pump();
final Offset secondLocation = _tester.getCenter(dropLocation);
await gesture.moveTo(secondLocation);
Widget locator of type Draggable<Student> This is the functionality UI
Snippet for above function callCode snippet
There are a few things that are potentially wrong with this code, but it's difficult to determine without more context.
Here, a possible solution for your use-case:
Defined the
targetFinder
anddropFinder
variables to represent the widgets being interacted with. These could be defined using a variety of methods, depending on the specific widget hierarchy and how the widgets are being tested.Removed the commented-out code and the
offset
variable, since they weren't being used in this snippet.Changed the
pointer
argument instartGesture
to use the default value ofnull
, since there was no particular reason to specify a pointer ID.Added error handling to the code (not shown in this snippet), such as checking that the
targetFinder
anddropFinder
variables are not null before using them. This could help prevent crashes and other unexpected behaviour.I hope this helps you out!