Вот функция сборки. Переменная newTaskTitle
, которая изначально имеет значение NULL, принимает значение из TextField. Но это значение не отражается в виджете Flat Button. Значение newTaskTitle
остается нулевым в виджете FlatButton. Помогите мне понять, где я ошибся.
Widget build(BuildContext context) {
String newTaskTitle;
return Container(
color: Color(0xFF757575),
child: Container(
padding: EdgeInsets.all(20),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(20),
topRight: Radius.circular(20),
),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Text(
'Add Task',
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.lightBlueAccent,
fontSize: 30,
),
),
TextField(
autofocus: true,
textAlign: TextAlign.center,
onChanged: (newText) {
newTaskTitle = newText;
print(newTaskTitle);
},
),
SizedBox(
height: 10,
),
FlatButton(
padding: EdgeInsets.all(10),
color: Colors.lightBlueAccent,
onPressed: () {
print(newTaskTitle);
addTaskCallback(newTaskTitle);
},
child: Text(
'Add',
style: TextStyle(
color: Colors.white,
fontSize: 20,
),
),
),
],
),
),
);
}
Чтобы клонировать проект, частично заполненный код можно найти здесь: https://github.com/vkmanojk/Flutter/tree/master/todoey_flutter
Заранее спасибо.