【问题标题】:Flutter how to make a variable private and initialize it with @required in constructorFlutter 如何将变量设为私有并在构造函数中使用 @required 对其进行初始化
【发布时间】:2019-09-14 14:59:40
【问题描述】:

如何将字段设为私有并在课堂上使用@required 对其进行注释?

例如,这段代码给了我错误:

class AuthenticationService {
  final Api _api;

  AuthenticationService({@required this._api}); // error in this line
}

【问题讨论】:

    标签: flutter dart


    【解决方案1】:
    class AuthenticationService {
      final Api _api;
    
      AuthenticationService({@required Api api}) : _api = api;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-08-17
      • 2011-03-18
      • 1970-01-01
      • 2013-07-19
      • 2020-09-27
      • 2015-02-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多