title: Why does the callback not have method variables in scope?
body: <p>In the below code, I want to be able to use the value that the user typed in when the button is clicked but <code>newTaskTitle</code> comes up as <code>null</code> inside the <code>onPressed</code> callback. <code>newTaskTitle</code> seems to be in scope in <code>onChanged</code> but not in <code>onPressed</code>. What am I missing here?</p>
  <pre><code>import 'package:flutter/material.dart';
  import 'package:todoey/constants.dart';
  
  class AddTaskSheet extends StatelessWidget {
    @override
    Widget build(BuildContext context) {
      String newTaskTitle;
  
      return Container(
        color: Color(0xff757575),
        child: Container(
          // constraints: BoxConstraints.,
          padding: EdgeInsets.all(30.0),
          ),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.stretch,
            mainAxisAlignment: MainAxisAlignment.start,
            children: &lt;Widget&gt;[
              Text(
                'Add Task',
                style: TextStyle(
                  fontSize: 30.0,
                  fontWeight: FontWeight.w500,
                  color: kAccentColour,
                ),
                textAlign: TextAlign.center,
              ),
              TextField(
                textAlign: TextAlign.center,
                onChanged: (value) {
                  newTaskTitle = value;
                  print(newTaskTitle);
                },
              ),
              SizedBox(
                height: 20,
              ),
              TextButton(
                style: ButtonStyle(
                  backgroundColor:
                      MaterialStateProperty.all&lt;Color&gt;(kAccentColour),
                ),
                onPressed: () {
                  print(newTaskTitle);
                  // Navigator.pop(context, newTaskTitle);
                },
                child: Text(
                  'Add',
                  style: TextStyle(
                    fontSize: 25.0,
                    color: Colors.white,
                  ),
                ),
              )
            ],
          ),
        ),
      );
    }
  }
  
  </code></pre>