Flutter solves the problem of incorrect use of parent datawidget and boundary constraint

Flutter solves the problem of incorrect use of parent datawidget and boundary constraint

The error information is as follows:

What about this kind of error

1 tells us that this error is related to the parent component, and then we can see 2 errors, and we can analyze the column – & gt under the page when loading the homepage written by ourselves; Container-> ConstrainedBox-> Expanded-> There is a problem with the subcomponents in the path of constrainedbox
the solution is to remove the expanded control and directly use it in constrainedbox
original code:

Container(
          // width: MediaQuery.of(context).size.width,
          height: 36.0,
          child: Expanded(
            flex: 1,
            child: ConstrainedBox(
              constraints: BoxConstraints.expand(),
              child: Stack(
                alignment: AlignmentDirectional.topCenter,
                children: [
                  Positioned(
                    child: Text("Recommendation",textDirection: TextDirection.ltr,style: TextStyle(fontSize: 20),),
                    left: 3.0,
                    top: 3.0,
                  ),
                  Positioned(
                      right: 3.0,
                      top: 3.0,
                      child: Container(
                        child:  Text("More",textDirection: TextDirection.rtl,style: TextStyle(fontSize: 16),),
                        /*Padding(
                        padding: EdgeInsets.all(4),
                        child:
                      ),*/
                        decoration: BoxDecoration(
                            border: Border.all(color: Colors.black87,width: 1.0,style: BorderStyle.solid),
                            borderRadius: BorderRadius.circular(20)
                        ),
                      )
                  )
                ],
              ),
            ),
          ),
       )

Modified code:

Container(
          // width: MediaQuery.of(context).size.width,
          height: 36.0,
          child: ConstrainedBox(
            constraints: BoxConstraints.expand(),
            child: Stack(
              alignment: AlignmentDirectional.topCenter,
              children: [
                Positioned(
                  child: Text("Recommendation",textDirection: TextDirection.ltr,style: TextStyle(fontSize: 20),),
                  left: 3.0,
                  top: 3.0,
                ),
                Positioned(
                    right: 3.0,
                    top: 3.0,
                    child: Container(
                      child:  Text("More",textDirection: TextDirection.rtl,style: TextStyle(fontSize: 16),),
                      /*Padding(
                        padding: EdgeInsets.all(4),
                        child:
                      ),*/
                      decoration: BoxDecoration(
                          border: Border.all(color: Colors.black87,width: 1.0,style: BorderStyle.solid),
                          borderRadius: BorderRadius.circular(20)
                      ),
                    )
                )
              ],
            ),
          )
       )

Why is this right
after a variety of baidu searches, it is found that the widget in flutter is rendered by the renderbox object at its bottom. The render box is constrained by its parent widget, and its size is adjusted according to these constraints. Constraints are composed of minimum width, maximum width, minimum height and maximum height; The size is composed of specific width and height

Read More: