[英]If BuildContext passed to build method refers to parent widget , then what does context passed to build() of root widget refer to?
Here is an example code:这是一个示例代码:
import 'package:flutter/material.dart';
main(){
runApp(MyApp());
}
class MyApp extends StatelessWidget {
build(context){ //where does this this context point to
return MaterialApp();
}
}
BuildContext构建上下文
A handle to the location of a widget in the widget tree.
Each widget has its own BuildContext, which becomes the parent of the widget returned by the StatelessWidget.build.每个小部件都有自己的 BuildContext,它成为 StatelessWidget.build 返回的小部件的父级。
BuildContext doesn't refer to the parent widget. BuildContext 不引用父小部件。 It refers to the current widget.
它指的是当前的小部件。
So with:所以:
class MyApp extends StatelessWidget {
build(context){ //where does this this context point to
return MaterialApp();
}
}
The BuildContext points to MyApp
. BuildContext 指向
MyApp
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.