Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is my RaisedButton not working in Flutter?

Tags:

flutter

dart

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,
      ),
  ),
like image 219
Juan Martin Zabala Avatar asked Oct 23 '25 22:10

Juan Martin Zabala


1 Answers

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.

like image 56
Lawan_L Avatar answered Oct 25 '25 12:10

Lawan_L