2021年2月2日星期二

How to initialize final properties in class constructor

I want to initialize a field by other field for example server URL and image URL should be also final

class Config {    final bool isDev = EnvironmentConfig.app_env == "development";    final bool isProd = EnvironmentConfig.app_env == "production";    final bool isQA = EnvironmentConfig.app_env == "qa";    String localHost = Platform.isAndroid ? "10.0.2.2" : "localHost";      String serverUrl;    String imageUrl;      Config() {      if (this.isDev) {        this.serverUrl = "http://$localHost:3000";      } else if (this.isProd) {        this.serverUrl = "";      } else if (this.isQA) {        this.serverUrl = "";      } else {        print("error: " + EnvironmentConfig.app_env);      }      this.imageUrl = this.serverUrl + "/api/files/image/";    }  }  
https://stackoverflow.com/questions/66015802/how-to-initialize-final-properties-in-class-constructor February 03, 2021 at 02:47AM

没有评论:

发表评论