简体   繁体   English

将 ListView.Builder 滚动方向从水平更改为垂直时出错

[英]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:此代码在 scrollDirection:Axis.horizonatal 时工作正常,但是当我制作 scrollDirection:Axis.verticle 时,这给了我错误,我已在代码下方发布:

  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.在 performLayout() 期间引发了以下断言:在布局期间,RenderStack object 被赋予了无限大小。

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.这可能意味着它是一个试图尽可能大的渲染 object,但它被放在另一个渲染 object 中,允许其子级选择自己的大小。 The nearest ancestor providing an unbounded height constraint is: RenderIndexedSemantics#94b2c relayoutBoundary=up3 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE... parentData: index=0;提供无界高度约束的最近祖先是: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) layoutOffset=0.0 (可以使用 size)... 约束: BoxConstraints(w=411.4, 0.0<=h<=Infinity)... 语义边界... size: MISSING... index: 0 应用于RenderStack 是: BoxConstraints(w=391.4, 0.0<=h<=Infinity) 它给出的确切大小是: 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.但是,我进行了一个测试,用固定大小的小部件替换了这些类(例如FadeAnimation类),并且代码正常工作。

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 .最后,我不认为你真的需要ConstrainedBox小部件,因为高度已经受到嵌套SizedBox的限制。 Hope this helps.希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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