Widget test failed while calling `longPress()'

Viewed 19

The Problem which I am facing when calling longPress:

The finder "zero widgets with key [<'owner_view_key'>] (considering only hit-testable ones)
(ignoring offstage widgets)" (used in a call to "longPress()") could not find any matching widgets.

My Widget Test:

testWidgets('test case for gestures', (tester) async {
await tester.setScreenSize();
await tester.testAppForWidgetTesting(OwnerView(
  nft: MOCK_NFT,
  ownerViewViewModel: viewModel,
));

await tester.pumpAndSettle();
final gestureDetectorOwnerScreen = find.byKey(const ValueKey(kOwnerViewKeyValue));
await tester.ensureVisible(gestureDetectorOwnerScreen);
await tester.pumpAndSettle(const Duration(seconds: 5));
await tester.longPress(gestureDetectorOwnerScreen.hitTestable());
await tester.pumpAndSettle();
});

My Widget:

  return Scaffold(
          backgroundColor: kBlack,
          body: GesturesForDetailsScreen(
            key: const ValueKey(kOwnerViewKeyValue),
            screen: DetailScreen.ownerScreen,
            viewModel: viewModel,
            nft: widget.nft,
            child:Container(...),
          ),
        );

This is my GesturesForDetailedScreen class:

 return GestureDetector(
  onTapUp: widget.tapUp,
  onHorizontalDragUpdate: widget.screen == DetailScreen.ownerScreen ? _onHorizontalDragUpdate : null,
  onHorizontalDragEnd: widget.screen == DetailScreen.ownerScreen ? _onHorizontalDragEnd : null,
  onHorizontalDragStart: widget.screen == DetailScreen.ownerScreen ? _onHorizontalDragStart : null,
  onVerticalDragUpdate: _onVerticalDragUpdate,
  onVerticalDragEnd: _onVerticalDragEnd,
  onVerticalDragStart: _onVerticalDragStart,
  onLongPressStart: _onLongPressStart,
  onLongPressEnd: _onLongPressEnd,
  child: widget.child,
);

Note: It is working fine when I give that key to any GestureDetector in my child

0 Answers
Related