title: How to pass device width to other screen inside initState in Flutter?
body: <p>I want to pass deviceWidth and deviceHeight to other screen. Here is my code:</p>
  <pre><code>class _SplashPageState extends State&lt;SplashPage&gt; {
    @override
    void initState(){
      super.initState();
  
      var deviceHeight = MediaQuery.of(context).size.height;
      var deviceWidth = MediaQuery.of(context).size.width;
  
      Future.delayed(Duration(seconds: 1), () async {
        await Navigator.pushNamed(context, &quot;/home&quot;);
      });
    }
  </code></pre>
  <p>But when I run this code, I am getting this error:</p>
  <pre><code>dependOnInheritedWidgetOfExactType&lt;MediaQuery&gt;() or dependOnInheritedElement() was called before _SplashPageState.initState() completed.
  </code></pre>
  <p>How to fix this? And the way I'm doing is right way?</p>