본문 바로가기

Flutter-플러터/플러터 공부

there isn't a setter named

반응형

there isn't a setter named 'totalinputPrice' in class 'IngredientController' Try correcting the name to reference an existing setter, or declare the setter 이 오류의 해결을 어떻게 할까

 

 

 

이 오류는 totalinputPrice 속성에 setter가 없기 때문에 발생합니다. totalinputPrice 속성에 setter를 추가하려면 다음과 같이 IngredientController 클래스를 수정해야 합니다.

 

class IngredientController {
  List<Ingredient> ingredients = [];

  double totalGramPrice = 0.0;
  double totalInputWeight = 0.0;

  double get totalInputPrice => totalInputPrice;

  set totalInputPrice(double value) {
    this.totalInputPrice = value;
  }

  void addIngredient(Ingredient ingredient) {
    ingredients.add(ingredient);
    totalGramPrice += ingredient.gramPrice;
    totalInputWeight += ingredient.inputWeight;
    totalInputPrice += ingredient.inputPrice;
  }
}

 

 

getter는 값을 가져올 때 

setter 값을 저장 할 때 

 

getter가 많이 쓰이고 setter 는 적게 쓰인다. 

반응형