The accepted should be didChangeDependencies
.
late Object args;
@override
void didChangeDependencies() {
args = ModalRoute.of(context).settings.argument
super.didChangeDependencies();
}
@override
Widget build(BuildContext context) {
/// use args here
}
It's mentioned in the docs
This method is also called immediately after initState. It is safe to call BuildContext.dependOnInheritedWidgetOfExactType from this method.
It's also mentioned in your error code
initialization based on inherited widgets can be placed in the didChangeDependencies is called after initState and whenever the dependencies change thereafter.