简体   繁体   中英

Getting error while changing ListView.Builder scroll direction from horizontal to verticle

Here is the code

This code is working fine when scrollDirection:Axis.horizonatal but when I make scrollDirection:Axis.verticle,this gives me error I've posted below the code:

  Widget build(BuildContext context) {
    return Scaffold(

      body: SingleChildScrollView(
        physics: BouncingScrollPhysics(),
        child: SafeArea(
          child: Column(
            children: <Widget>[
              FadeAnimation(1.4, HeaderWidget()),
              SizedBox(height: 30),
              FadeAnimation(1.8,SearchWidget()),
              SizedBox(height: 30,),
              FadeAnimation(1.8,Text(
                'Here is the list of items',
                style: TextStyle(color: Colors.grey[800],
                  fontWeight: FontWeight.w900,
                  fontStyle: FontStyle.italic,
                  fontFamily: 'Open Sans',),
              )),
              SizedBox(height: 30,),
              Container(
                height: 130,
                child: shopDetailsList.length==0?new Text("Data no available"):SingleChildScrollView(
                  child: ConstrainedBox(
                    constraints: BoxConstraints(),
                    child: SizedBox(
                      height: 130,
                      child: new ListView.builder(
                        itemCount: shopDetailsList.length,
                        scrollDirection: Axis.vertical,<--------------------
                        itemBuilder: (_,index){

                          return ShopDetailsUI(shopDetailsList[index].Name,shopDetailsList[index].ShopName,shopDetailsList[index].ShopNumber,shopDetailsList[index].ShopState,shopDetailsList[index].ShopStreet,shopDetailsList[index].ShopType);
                        },
                      ),
                    ),
                  ),
                ),
              ),


            ],
          ),
        ),

     )

    );

Error

The following assertion was thrown during performLayout(): RenderStack object was given an infinite size during layout.

This probably means that it is a render object that tries to be as big as possible, but it was put inside another render object that allows its children to pick their own size. The nearest ancestor providing an unbounded height constraint is: RenderIndexedSemantics#94b2c relayoutBoundary=up3 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE... parentData: index=0; layoutOffset=0.0 (can use size)... constraints: BoxConstraints(w=411.4, 0.0<=h<=Infinity)... semantic boundary... size: MISSING... index: 0 The constraints that applied to the RenderStack were: BoxConstraints(w=391.4, 0.0<=h<=Infinity) The exact size it was given was: Size(391.4, Infinity)

I tried to replicate your problem without any success since some definitions are missing in the code you've provided. However, I ran a test replacing those classes (eg the FadeAnimation class) with fixed-sized widgets and the code worked without any exception.

As a general tip, try decomposing your code in smaller parts and simplify those that you think are not needed. You may, for example, try running the app with only the top-level widgets and step-by-step adding its children. In this way you should be able to self diagnose where is the problem.

Finally, I don't think you really need the ConstrainedBox widget as the height is already being constrained by the nested SizedBox . Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM