Я создаю приложение, в котором пользователь вводит текст в текстовые поля. Есть 3 текстовых поля. Я хочу, чтобы вводимый текст, который вводится в текстовые поля, был сохранен в списке. Я пытаюсь сделать это, запустив код ниже. Но он всегда выводит пустой список. Кажется, не могу найти проблему.
class _ListPageState extends State<ListPage> {
List<String> items = [];
var counter = 0;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('Create Your Need List', style: TextStyle(color: Colors.grey[500]),), backgroundColor: Colors.white, elevation: 0,),
body: Padding(
padding: const EdgeInsets.fromLTRB(15, 25, 15, 0),
child: Column(
children: <Widget>[
TextField(
decoration: InputDecoration(
border: OutlineInputBorder(),
hintText: 'Add item'
),
onChanged: (String str){
setState(() {
items[counter] = str;
counter +=1;
});
},
),
TextField(
decoration: InputDecoration(
border: OutlineInputBorder(),
hintText: 'Add item'
),
onChanged: (String str){
setState(() {
items[counter] = str;
counter +=1;
});
},
),
TextField(
decoration: InputDecoration(
border: OutlineInputBorder(),
hintText: 'Add item'
),
onChanged: (String str){
setState(() {
items[counter] = str;
counter +=1;
});
},
),
SizedBox(height: 10,),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: () {
Navigator.pushAndRemoveUntil(context, SlideFromLeft(widget: Dashboard()), ModalRoute.withName('/dashboard'));
print(items);
},
child: Icon(Icons.navigate_next),
backgroundColor: Colors.pink,
)
);
}
}