繁体   English   中英

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

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

这是代码

此代码在 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);
                        },
                      ),
                    ),
                  ),
                ),
              ),


            ],
          ),
        ),

     )

    );

错误

在 performLayout() 期间引发了以下断言:在布局期间,RenderStack object 被赋予了无限大小。

这可能意味着它是一个试图尽可能大的渲染 object,但它被放在另一个渲染 object 中,允许其子级选择自己的大小。 提供无界高度约束的最近祖先是:RenderIndexedSemantics#94b2c relayoutBoundary=up3 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE... parentData: index=0; 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)

我试图复制您的问题但没有成功,因为您提供的代码中缺少一些定义。 但是,我进行了一个测试,用固定大小的小部件替换了这些类(例如FadeAnimation类),并且代码正常工作。

作为一般提示,请尝试将您的代码分解成更小的部分,并简化您认为不需要的部分。 例如,您可以尝试仅使用顶级小部件运行应用程序并逐步添加其子级。 通过这种方式,您应该能够自我诊断问题出在哪里。

最后,我不认为你真的需要ConstrainedBox小部件,因为高度已经受到嵌套SizedBox的限制。 希望这可以帮助。

暂无
暂无

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

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