For newcomers, you have access to context in initState as others said. The only problem here in initState build function is not executed yet. So this context is kind of empty.
To solve this, you can use SchedulerBinding:
SchedulerBinding.instance.addPostFrameCallback((_) => doSomethingNextFrame(context));
addPostFrameCallback: Schedule a callback for the end of this frame.
Future.delayed(Duration.zero)
will also work. But I think SchedulerBinding looks cleaner.