I have been working on a to-do list app in Flutter but in the process, I realized that the add button was not working when it was supposed to add a new task. I don't know why it doesn't work, because I am very new to Flutter. Why is this problem occurring!?
main.dart
List<String> _toDoItems = [];
void _addToDoItem(String task) {
if(task.length > 0) {
setState(() {
_toDoItems.add(task);
});
}
}
Expanded(
flex: 8,
child: TextField(
autofocus: true,
onSubmitted: (val) {
_addToDoItem(val);
},
),
),
Expanded(
flex: 2,
child: RaisedButton(
child: Text('ADD'),
onPressed: () => _addToDoItem,
),
),
The RaisedButton widget was deprecated in Flutter 2.0 and replaced with the ElevatedButton widget. It's possible that you're using a newer version of Flutter where RaisedButton is no longer available. Try using ElevatedButton instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With