简体   繁体   English

如果传递给 build 方法的 BuildContext 是指父窗口小部件,那么传递给根窗口小部件的 build() 的上下文是指什么?

[英]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.

相关问题 什么上下文名称应该传递给Glide方法? - What context name should be passed to Glide method? 是否有一个小部件来执行此操作,或者我将如何构建此行为 - Is there a widget that does this, or how would i build this behaviour 为什么上下文会传入此方法 - Why is context getting passed in to this method 错误的项目从窗口小部件传递到活动 - Wrong item being passed to activity from widget 什么是传递给BroadcastReceiver的onReceive()的Context? - What is the Context passed into onReceive() of a BroadcastReceiver? 如何构建一个简单的 Android 小部件 - How to build a Simple Android Widget Android N(预览版)在“构建目标”下指的是什么 - What does Android N (Preview) refer to under “Build target” Flutter 中的参数类型“Widget Function(BuildContext)”无法分配给参数类型“Widget Function(BuildContext, Widget)”错误 - The argument type 'Widget Function(BuildContext)' cant be assigned to the parameter type 'Widget Function(BuildContext, Widget)' Error in Flutter 传递给getAssets()方法的上下文为null - Context being passed into method for getAssets() is null Android:传递给方法时上下文为空 - Android: Context is null when passed to method
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM