기초 내용
레이아웃 작성
https://landroid.tistory.com/20
프로젝트
해당 클래스를 State<>으로 privite ( _classname) 로 넘겨주고
멤버 함수 안에서 setState로 변경된 함수를 업데이트한다
class _DiceRollerState extends State<DiceRoller> {
int currentDice = 3 ;
var Diceimage = 'assets/images/dice-3.png';
void rollDice() {
int currentDice = randomizer.nextInt(6)+1 ; //nextInt(max) >> 0~ max 상성
setState(() {
Diceimage = 'assets/images/dice-${currentDice}.png';
});
print('Change Dice to $currentDice');
}
Every Flutter Widget has a built-in lifecycle: A collection of methods that are automatically executed by Flutter (at certain points of time).
There are three extremely important (stateful) widget lifecycle methods you should be aware of:
initState()
: Executed by Flutter when the StatefulWidget's State object is initializedbuild()
: Executed by Flutter when the Widget is built for the first time AND after setState()
was calleddispose()
: Executed by Flutter right before the Widget will be deleted (e.g., because it was displayed conditionally)