I'm trying to create a list in flutter then add items to it . But the problem is I'm facing an error in the editor (Android Studio) . It says "Invalid constructor name" .
Here's my code format :
List<String > list = new List<String>();
list.add(" ");
The error says that you are trying to write a method call in the class body. You should add items to the list in the body of the appropriate method. Only constructor calls are allowed in the class body.
class Wrong {
List<String > list = new List<String>();
list.add(""); // error: Invalid constructor name
}
class Ok {
List<String > list = new List<String>();
initState() {
list.add("");
}
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments