我正在尝试通过以下方式创建服务器列表:
class Server {
final String country;
final String ip;
final String username;
final String password;
const Server(
{required this.country, required this.ip, required this.username, required this.password});
static List<Server> allServers() {
var myServers = new List<Server>();
myServers.add(const Server(
country: "Italy"
ip: "1.2.3.4.example.com",
username: "user1",
password: "password1"
));
myServers.add(const Server(
country: "United States",
ip: "5.6.7.8.example.com",
username: "user2",
password: "password2"
));
return myServers;
}
}
我收到错误“类‘List’没有未命名的构造函数”
我该如何修复它?
提前致谢
您的代码几乎正确,但是您遵循了错误的语法。
请参考以下示例。我刚刚重新起草了您的示例