'widget tester cannot tap widget that is on the screen, when has a child rive animation
I have a custom button that runs a Rive animation every x secs, and if pressed will show a modal sheet. The button is wrapped in a gesture detector.
I have a problem testing the button since the tester is failing to tap
my button widget:
@override
void initState() {
super.initState();
megaMenuDurationIntervalInSeconds = 60;
_controller = OneShotAnimation(
AssetPaths.megaMenuButtonAnimationName,
autoplay: false,
onStop: () => setState(() => _isPlaying = false),
onStart: () => setState(() => _isPlaying = true),
);
_timer = Timer.periodic(const Duration(seconds: 60), (Timer t) => _runAnimation());
}
@override
Widget build(BuildContext context) {
return SizedBox(
width: widget.dimensions,
height: widget.dimensions,
child: RiveAnimation.asset(
AssetPaths.megaMenuButtonRive,
onInit: (_) => setState(() {}),
animations: const [AssetPaths.megaMenuButtonAnimationName],
fit: BoxFit.contain,
controllers: [_controller],
),
);
}
and my test fails
testWidgets('navigates to checks menu', (WidgetTester tester) async {
await _buildAndOpenMegaMenu(tester);
expect(find.byType(MegaMenuButtonRive), findsOneWidget);
await tester.tap(find.byType(MegaMenuButtonRive));
await tester.pump();
A call to tap() with finder "exactly one widget with type "MegaMenuButtonRive" derived an Offset (Offset(400.0, 300.0)) that would not hit test on the specified widget.
Basically, calling tap on a widget that has a rive animation doesn't recognize the tap. If I replaced the rive animation with any random widget it works fine. Any ideas why this happens, I have tried several approaches but none worked
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
