title: Problem with local variable - Global variable flutter dart
body: <p>I want to pass dynamic data through different pages, when using a <code>BottomAppBar</code>. I currently switch between pages/widgets my storing them like this:</p>
  
  <pre><code>  @override
    void initState() {
      super.initState();
      final _pageOptions = [
      SwipeScreen(currentUserId: currentUserId),
      Requests(currentUserId: currentUserId),
      Messages(currentUserId: currentUserId),
      Settings(),
    ];}
  </code></pre>
  
  <p>I then use <code>_pageOptions</code> in my <code>Scaffold</code>:</p>
  
  <pre><code>  body: _pageOptions[_selectedPage],
    bottomNavigationBar: BottomNavigationBar(
      currentIndex: _selectedPage,
      onTap: (int index) {
        setState(() {
          _selectedPage = index;
        });
      },
  </code></pre>
  
  <p>As you may have guessed, I can't use <code>_pageOptions</code> as my body in my <code>Scaffold</code>, as it is a local variable when wrapped in an <code>initState()</code>. I have to use this initState though, as without it, I can only pass static members in my initializers. </p>
  
  <p>I don't know how to fix this, as removing one just gives me a different error. I have looked for ways to make a variable global, for example having <code>_pageOptions</code> in a different file, but then it was still local, and therefore not defined when used in my <code>Scaffold</code>.</p>
  
  <p>I hope my problem is clear.</p>
  
  <p>Thanks in advance.</p>