반응형
공식 홈페이지
A handle to the location of a widget in the widget tree
위젯 트리에서 현재 위젯의 위치를 알 수 있는 핸들(정보)이다
class MainPage extends StatelessWiget {
@override
Widget build(BuildContext) {
return Scaffold();
}
}
Build method는 Scaffold Widget을 return하는데, 이 때 Widget tree상에서 어디 위치하는지에 대한 정보를 가지고있는 context를 넘겨주게 된다.
Each widget has its own BuildContext, which becomes the parent of the widget returned by the StatelessWidget.build or State.build function
이 BuildContext는 stateless Widget이나 state build method에 의해 return된 Widget의 부모가 된다.
class MainPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold();
}
}
MainPage라는 Widget도 자신의 BuildContext를 가지고 있다.
Build method를 통해서 Scaffold Widget이 부모격인 MainPage의 BuildContext를 그대로 물려받게 된다.
반응형
'Flutter > Flutter Dart Tip' 카테고리의 다른 글
[ Flutter ] PATH 오류 (0) | 2022.02.06 |
---|