본문 바로가기

완료한 프로젝트/프로젝트 1 : 부가세 계산기

승민님의 원가계산기 코드 참고하기 1 - 모델

반응형

 

승민님의 원가계산기 코드를 찬찬히 읽어보고 공부 할 계획이다. 

끝내고 나면 많은 도움이 될 것 같다. 

 

 

 

 

 

Ingredient 모델 

 

먼저 구현하고자 하는 기능은 

알럿창을 띄워서 재료 하나하나 이름, 가격, 중량, 가격, 브랜드를 입력하게 한다. 

그리고 저장 버튼을 누르면 해당 중량/가격 = g당 가격을 구하게 한다. 

그리고 텍스트 필드 필요한 투입량을 넣으면 해당 재료가 그 레시피에 들어가는 총 가격이 구해지게 하는 것. 

 

 

 

 

- 나는 ingredient 모델을 만들고 

ingredientList 모델도 만들어서 리스트 따로 데이터 따로 관리해야 하는 줄 알았다. 하지만 승민님은  

 

Ingredient 모델에 g당 가격, 총 가격까지 하나의 모델로 구성을 했다. 

 

 

 

class DtoIngredient {
  dynamic createdDate;
  String? ingredientName;
  double? weight;
  double? price;
  String? brand;
  double? inputUnit;
  double? pricePerGram;
  double? totalPrice;
  String? id;

  DtoIngredient(
      {required this.createdDate,
      required this.ingredientName,
      required this.weight,
      required this.price,
      required this.brand,
      required this.inputUnit,
      required this.pricePerGram,
      required this.totalPrice,
      this.id});

 

 

나의 원가계산기에는 두 가지 레시피 입력이 존재한다. 

1. 소스 레시피 

2. 메뉴 레시피 

 

음식을 할 때 가장 중요한 건 

소스 이다. 

 

즉 자신만의 가게의 소스를 만들 때 들어가는 원가를 구하고 

그 소스를 이용한 메뉴 레시피의 원가를 계산 할 때 소스 레시피를 불러오게 하면 좋을 것 같다는 생각이 들었다. 

 

그래서 승민님은 아래와 같이  소스, 메뉴 모델을 각각 만들었다. 

 

 

아래의 변수 값에는 

소스 이름, 재료의 총 무게, g당 가격의 합, 총 원가 합계가 들어 간다. 

 

메뉴 모델 안에는 소스 레시피의 List가 들어가 있다. 

 

 

 

 

class DtoSauce {
  String? createdAt;
  String? lastUpdatedDate;
  String? sauceName;
  double? totalWeight;
  double? pricePerGram;
  double? totalPrice;
  String? id;

  DtoSauce(
      {required this.createdAt,
      required this.lastUpdatedDate,
      required this.sauceName,
      required this.totalWeight,
      required this.pricePerGram,
      required this.totalPrice,
      this.id,});
      
      
      import 'package:flutter/material.dart';

class DtoMenu {
  Timestamp? createdAt;
  Timestamp? lastUpdatedDate;
  String? menuName;
  double? totalWeight;
  double? pricePerGram;
  double? totalPrice;
  int? ingredientQuantity;
  String? id;
  List<String>? sauceIdList;

  DtoMenu(
      {required this.createdAt,
      required this.lastUpdatedDate,
      required this.menuName,
      required this.totalWeight,
      required this.pricePerGram,
      required this.totalPrice,
      required this.ingredientQuantity,
      this.id,
      this.sauceIdList});

 

 

 

728x90
반응형