On the dynamic acquisition of expandedheight of sliderappbar in nestedscrollview

When using nested Scrollview to collapse a writing project, we encounter a problem. The content in flexible spacebar needs to be displayed dynamically. Some data needs to be returned, which may be hidden. As a result, the height is uncertain. However, expandedheight in slicerappbar can only be fixed, so we have to find another way to obtain the height.

 

    copy a copy of the code in flexible space bar and write it into a statelesswidget to set a globalkey. Now you need to process the request, write it in the successful callback, and use the first frame of the successful request to get the height

    WidgetsBinding.instance.addPostFrameCallback((_) {
          RenderBox _cardBox =
              _flexibleSpaceBarKey.currentContext.findRenderObject();
    
          Future.delayed(Duration(milliseconds: 10), () {
            setState(() {
              heightFlexibleSpaceBar = _cardBox.size.height;
            });
          });
        });

Read More: