Contents
1. 이름있는 생성자1. 이름있는 생성자
// 이름이있는 생성자
class Button {
String text;
String color;
int x;
int y;
int width;
int height;
Button(
this.text, {
this.color = "회색",
this.x = 0,
this.y = 0,
this.width = 200,
this.height = 150,
});
Button.block(
this.text, {
this.color = "회색",
this.x = 0,
this.y = 0,
this.width = 100000000,
this.height = 150,
});
static Button inlineButton(String text) {
return Button(text);
}
}
void main () {
Button basicButton = Button("로그인");
Button redButton = Button("로그인", color: "red");
Button blockButton = Button("회원가입");
Button inlineButton = Button.inlineButton("회원가입");
print(blockButton.text); // 회원가입
print(inlineButton.text); // 회원가입
}
이름있는 생성자와 static으로 만든 메서드를 구분 잘하자.
Share article