title: Flutter: Use choice function with PopupMenuButton to navigate to another page
body: <p>I am trying to navigate back to the login page from a 'Sign Out' button on a PopupMenuButton list located on the app's homepage. The SignOut button I'm trying to configure looks like this: </p>
  
  <p><a href="https://i.stack.imgur.com/PzZVb.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/PzZVb.png" alt="enter image description here"></a></p>
  
  <p>The simplified code looks like this:</p>
  
  <pre><code>@override
  Widget build(BuildContext context) {
  return Scaffold(
      appBar: AppBar(
        title: Text('Home Page'),
        actions: &lt;Widget&gt;[
          PopupMenuButton&lt;String&gt;(
            onSelected: choiceAction,
            itemBuilder: (BuildContext context) {
              return MenuOptions.choices.map((String choice){
                return PopupMenuItem&lt;String&gt;(
                  value: choice,
                  child: Text(choice),
                );
              }).toList();
  </code></pre>
  
  <p>and  <code>onSelected</code> calls the following <code>choiceAction</code>:</p>
  
  <pre><code>  void choiceAction(String choice) {
      setState() {
        if (choice == MenuOptions.SignOut) {
          Navigator.push(
            context,
            MaterialPageRoute(builder: (context) =&gt; LoginPage()),
          );
        }
      }
    }
  </code></pre>
  
  <p>The problem I'm facing is that it says <code>context</code> in Navigator.push is undefined. I'm not sure if I use the context defined in <code>Widget build(BuildContext context)</code> or <code>itemBuilder: (BuildContext context)</code> and I am lost on how I would fix the error that its undefined to make it use the definition where its being called in <code>onSelected</code>.</p>