Тест виджета Flutter: следующая ошибка NoSuchMethodError была выбрана при построении RegistrationForm(состояние: RegistrationFormState#12e12)
У меня есть виджет RegistrationScreen с эшафотом, тело которого отображает другой виджет, RegistrationForm:
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,
)
);
}
}
Мой тест на флаттер:
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);
});
Сразу выдает исключение:
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
Это предшествует любому утверждению и ясно указывает на проблему, связанную с тем, что RegistrationForm является виджетом с отслеживанием состояния. Как правильно справиться с подобным сценарием? Можно ли заглушить дочерние виджеты, внутреннее устройство которых не требуется для этого теста?