Variable value gets null outside setState() in Flutter

                                        style: TextStyle(
                                            fontFamily: "Averta",
                                            fontWeight: FontWeight.bold,
                                            fontSize: 16,
                                        enableSuggestions: true, 

                                        onChanged: (value) {
                                          setState(() {
                                            final title = value;

                                        decoration: InputDecoration(
                                          border: InputBorder.none,
                                          hintText: "Enter Task Title",
                                          hintStyle: TextStyle(
                                              fontFamily: "Averta",
                                              fontWeight: FontWeight.normal,
                                              fontSize: 12,
                                              color: Colors.grey.shade300),

Here,I have a title variable which I update with onChanged() function. Here the print() function shows exact change in value which I do in TextField. But I don't want to pass it here, I want to take some more data and then pass it when I click the CREATE button here-

                                    onTap: () {
                                            setState(() {
                                              DatabaseHelper _dbhelper =
                                              Task _newTask = Task(
                                                  title: title,
                                                  year: year,
                                                  month: month,
                                                  day: daye,
                                                  hour: hour,
                                                  minute: minute,
                                                  weekday: weekday);

Here the print statement shows "null",but I want to use the value which was updated above in TextField. How can I achieve this in Flutter?

Read more here:

Content Attribution

This content was originally published by Durgesh Kudalkar at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: