I recently had the same exception when I was trying to navigate to another route from a Stateful Widget. Turns out I had forgotten to add the line super.initState(); at the start of my widget’s initState()
Once I change it to this it worked perfectly
@override
void initState() {
super.initState();
....
}