개발일지
Dartlang class에 Object를 argument로 넘겨주기
케이오스
2021. 6. 20. 21:24
딴지, 훈수 대환영입니다.
문제 있으면 지적해주세요 굽신굽신..
class Shop {
final dynamic shopObject;
late final int id;
late final String shopCode;
late final String shopName;
late final String address;
late final bool authorized;
late final bool publicShop;
late final String shopImage;
Shop({required this.shopObject}){
assert(shopObject != null, 'shop object is not nullable');
assert(shopObject['id'] != null, 'shop id is not nullable');
assert(shopObject['shopCode'] != null, 'shopCode is not nullable');
assert(shopObject['shopName'] != null, 'shopName is not nullable');
assert(shopObject['address'] != null, 'address is not nullable');
assert(shopObject['authorized'] != null, 'authorized is not nullable');
assert(shopObject['publicShop'] != null, 'publicShop is not nullable');
assert(shopObject['shopImage'] != null, 'shopImage is not nullable');
id = shopObject['id']!;
shopCode = shopObject['shopCode'];
shopName = shopObject['shopName'];
address = shopObject['address'];
authorized = shopObject['authorized'];
publicShop = shopObject['publicShop'];
shopImage = shopObject['shopImage'];
}
Map<String, dynamic> toMap(){
return {
'id': id,
'shopCode': shopCode,
'shopName': shopName,
'address': address,
'authorized': authorized,
'publicShop': publicShop,
'shopImage': shopImage,
};
}
}
이렇게 하면 쉽게 arguments 를 넣고, 사용할 수 있음.
근데, 여기 저기 뒤져봐도 이렇게 사용하는 코드를 못 봐서 뭔가 문제가 있지 않나 싶어 불안 불안합니다.
근데 왜 이거 실제로 글을 발행하면, 코드블록이 흑백으로 바뀌는지...ㅜㅜ
==> 티스토리 관리자에서 플러그인 -> 코드 하이라이트 설치해주니 칼라풀하게 나옴