반응형
승민님의 원가계산기 코드를 보고 원가계산기를 만들 생각이다.
승민님의 재료 모델 클래스
생성되는 날짜의 변수 값을 dynamic
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});
DtoIngredient.fromJson(Map<String, dynamic> json, String? _id)
: createdDate = json['createdDate'],
ingredientName = json['ingredientName'],
weight = json['weight'],
price = json['price'],
brand = json['brand'],
inputUnit = json['inputUnit'],
pricePerGram = json['pricePerGram'],
totalPrice = json['totalPrice'],
id = _id;
Map<String, dynamic> toJson() => {
'createdDate': createdDate,
'ingredientName': ingredientName,
'weight': weight,
'price': price,
'brand': brand,
'inputUnit': inputUnit,
'pricePerGram': pricePerGram,
'totalPrice': totalPrice,
};
}
소스에 들어가는 메뉴 클래스
import 'package:flutter/material.dart';
import 'dto_ingredient.dart';
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,});
DtoSauce.fromJson(Map<String, dynamic> json,String _id)
: createdAt = json['createdAt'],
lastUpdatedDate = json['lastUpdatedDate'],
sauceName = json['sauceName'],
totalWeight = json['totalWeight'],
pricePerGram = json['pricePerGram'],
totalPrice = json['totalPrice'],
id = _id;
Map<String, dynamic> toJson() => {
'createdAt': createdAt,
'lastUpdatedDate': lastUpdatedDate,
'sauceName': sauceName,
'totalWeight': totalWeight,
'pricePerGram': pricePerGram,
'totalPrice': totalPrice,
};
}
메뉴 클래스 -> 이 안에 소스 메뉴의 리스트를 넣어놨다.
이러면 후에 메뉴를 만들 때 소스 메뉴를 선택 할 수 있게 된다.
import 'package:cloud_firestore/cloud_firestore.dart';
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});
DtoMenu.fromJson(Map<String, dynamic> json)
: createdAt = json['createdAt'],
lastUpdatedDate = json['lastUpdatedDate'],
menuName = json['menuName'],
totalWeight = json['totalWeight'],
pricePerGram = json['pricePerGram'],
totalPrice = json['totalPrice'],
ingredientQuantity = json['ingredientQuantity'],
sauceIdList = json['sauceIdList'];
Map<String, dynamic> toJson() => {
'createdAt': createdAt,
'lastUpdatedDate': lastUpdatedDate,
'menuName': menuName,
'totalWeight': totalWeight,
'pricePerGram': pricePerGram,
'totalPrice': totalPrice,
'ingredientQuantity': ingredientQuantity,
'sauceIdList': sauceIdList,
};
}
반응형
'진행중인 프로젝트 > 프로젝트 2 : 원가 계산기' 카테고리의 다른 글
원가계산기 5번째 도전 (0) | 2023.07.23 |
---|---|
외식업 원가계산기 진행 요약 (0) | 2023.05.21 |
원가계산기 진행상황 3 : 알럿창을 리스트 타일 안에서 만들어보기 (0) | 2023.02.21 |
원가계산기 진행상황 2 : onchange 이용하기 (0) | 2023.02.20 |
원가계산기 진행상황 1 : 리스트 안에 리스트? (0) | 2023.02.19 |