본문 바로가기
[Flutter]

setState 원리

by Hevton 2021. 10. 29.
반응형

https://codinghub.tistory.com/180

 

setState 원리 (setState Principle)

setState 원리 (setState Principle) [Ko]  - flutter는 Stateful widget과 Stateless widget을 가지며, Stateful widget만이 상태를 가질 수 있다. 상태 정보를 새로 반영하기 위해서는 setState가 실행되면..

codinghub.tistory.com

 

 

setState 동작 순서..?

onPressed() {
	setState( () { ~~~ } );
	// 이부분은 건너뛰는지
}

=> 안건너뛴다고 함. 자세힌 모르겠네.. 아래를 참고하라고 하심.

 

https://api.flutter.dev/flutter/widgets/State/setState.html

 

setState method - State class - widgets library - Dart API

void setState(VoidCallback fn ) Notify the framework that the internal state of this object has changed. Whenever you change the internal state of a State object, make the change in a function that you pass to setState: setState(() { _myState = newValue; }

api.flutter.dev

 

 

화면에 a의 값을 텍스트로 뿌려주고
a =1
setState()
a=2
이런코드가 있따하면

 

화면에는 1로뜨는데 값은 2를 갖고있다라고

 

a=2가 실행은됩니다. 화면 빌드가 안됐을뿐

반응형