Flutter widget test - Can't tap offstage button

Viewed 615

Here's the widget:

  Widget _buildButton() {
    return Offstage(
      offstage: this._isOffstage,
      child: TextButton(
        key: Key('myBtn'),
        child: Text('Click'),
        onPressed: () {
          print('PRESSED');
        },
      ),
    );
  }

In my test:

final btnFinder = find.byKey(Key('myBtn'), skipOffstage: false);

expect(btnFinder, findsOneWidget);
await tester.tap(btnFinder);

For context, the _isOffstage flag is false, and the test passes. However, the print in the onPressed is never printed but I don't get any warnings that the button was missed. There's another button in this widget that is not wrapped in an Offstage that can be tapped, so what do I need to do differently for buttons wrapped in Offstage?

0 Answers
Related