I am trying to add a simple test to verify the login page shows when opened (as per the example test available on Flutter).
I get the following error, caused by the state_widget static _StateWidgetState data call:
static _StateWidgetState of (BuildContext context) {
return (context.inheritFromWidgetOfExactType(_StateDataWidget)
as _StateDataWidget)
.data;
}
This is the error message:
══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
The following NoSuchMethodError was thrown building RootScreen(dirty, state:
_RootScreenState#941dc):
The getter 'data' was called on null.
Receiver: null
Tried calling: data
When the exception was thrown, this was the stack:
#0 Object.noSuchMethod (dart:core/runtime/libobject_patch.dart:50:5)
#1 StateWidget.of (package:mama_fit_club/state_widget.dart:28:10)
This is the simple test:
void main() {
testWidgets('Test login page displayed', (WidgetTester tester) async {
// Build our app and trigger a frame.
await tester.pumpWidget(StateWidget(child: MyApp()));
final loginRequestFinder = find.text("To continue please login with");
expect(loginRequestFinder, findsOneWidget);
});
}
Are you able to help? I need to add tests to my app.
Thanks!