0
votes

I have a SignupScreen Widget with a Scaffold that has a body which renders another Widget, SignupForm:

class SignupScreen extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: MainAppBar(title: 'Create Account'),
      body: Center(
        child: SignupForm()
      ),
      floatingActionButton: FloatingActionButton.extended(
        onPressed: () {
          Navigator.pushReplacementNamed(context, '/users');
        },
        label: Text('Skip'),
        icon: Icon(Icons.home),
        backgroundColor: Theme.of(context).primaryColor,
      )
    );
  }
}

My flutter test:

Widget createTesterWidget({Widget child}) {
  return MaterialApp(
    home: child,
  );
}

testWidgets('Passes "Create Account" text to MainAppBar', (WidgetTester tester) async {
  await tester.pumpWidget(createTesterWidget(child: SignupScreen()));

  var mainAppBar = find.widgetWithText(MainAppBar, 'Create Account');
      
  expect(mainAppBar, findsOneWidget);
});

Immediately throws the exception:

The following NoSuchMethodError was thrown building SignupForm(state: SignupFormState#12e12):
The getter 'value' was called on null.
Receiver: null
Tried calling: value

The relevant error-causing widget was:
  SignupForm

This is prior to any assertion and clearly indicates an issue with the SignupForm being a Stateful Widget. What's the proper way to handle a scenario like this? Is it possible to stub out child widgets whose internals are not needed for this test?