Testing whether widgets are visible onscreen

Hi,
I’m trying to create a test that checks if a widget is visible on a page. I created an if statement to check but keep getting an error that a widget cannot equal null.

  1. What have I tried so far -

if (kNavigationMenu != Visibility) {
await btnTap(kNavigationMenu);
}
await btnTap(kAdminButton);

And

  if (kNavigationMenu != false) {
    await btnTap(kNavigationMenu);
  }

  await btnTap(kAdminButton);

I keep getting this error:

The finder “zero widgets with widget matching predicate (Closure:
(Widget) => bool from: widget => {
if (widget == null) dart.nullFailed(I[0], 215, 15,
“widget”);
return tooltip.Tooltip.is(widget) && widget.message ==
message;
}) (ignoring offstage widgets)” (used in a call to “tap()”)
could not find any matching widgets.

Is there a way to check if the widget is visible or exists?

Not sure about the test cases, but this plugin can help you print visibility changes of a widget:

visibility_detector: ^0.2.0