类错误“必须提供函数体”

Gra*_*und 1 class dart flutter

我想做的就是添加一个包含字符串列表的新类。一切正常,除了我的类上出现错误,说它需要在最后一个“}”上有一个函数体。我遵循了一个教程,它几乎完全匹配。在教程中,代码不需要在参数之前添加“必需”语句。添加“必需”后,这些错误消失了,但函数体错误仍然存​​在。这是代码:

class LoginInfo {

  String website;
  String username;
  String password;

  LoginInfo(
      {required this.website, required this.username, required this.password})

}
Run Code Online (Sandbox Code Playgroud)

Est*_*ñoz 9

问题是您忘记;在构造函数的末尾添加 a 。

这样做问题就消失了:

class LoginInfo {

  String website;
  String username;
  String password;

  LoginInfo(
      {required this.website, required this.username, required this.password});

}
Run Code Online (Sandbox Code Playgroud)