将布局视图添加到布局颤动的中间

问题描述 投票:0回答:1

我想在页面的其他项目之间显示我的列表视图。我的基本流程现在就这样:

AppBar Body:
-Image
-Title
-IntroText
-NEED LIST VIEW HERE

以下是我的窗口小部件和布局:

ListView _buildSectionList(List<Sections> sections, context) {
  print(sections.length);
  return ListView.builder(
    itemCount: sections.length,
    itemBuilder: (BuildContext context, int index) {
      return new Column(
        children: <Widget>[
          new ListTile(
            leading: Text(index.toString()),
            title: new Text(
              (sections[index].content),
              style: TextStyle(
                  fontSize: 18,
                  fontWeight: FontWeight.bold,
                  color: Colors.white),
            ),
          ),
          new Divider(
            height: 12.0,
            color: Colors.white,
          ),
        ],
      );
    },
  );
}

如果我仅将_buildSectionList插入主体,它将显示数据就好。

但是,当我将其添加到下面的布局中时,出现错误(在布局下方):

children: <Widget>[
                      Padding(
                        padding: EdgeInsets.only(top: 0.0, bottom: 15.0),
                        child: Align(
                          alignment: Alignment.centerLeft,
                          child: Text(
                            title.toUpperCase(),
                            style: TextStyle(
                                fontSize: 24,
                                fontWeight: FontWeight.bold,
                                color: Colors.black54),
                            textAlign: TextAlign.left,
                          ),
                        ),
                      ),
                      Text(landingpagecontent, style: TextStyle(fontSize: 18)),
                      _buildSectionList(sections,context),
                      Row(
                        crossAxisAlignment: CrossAxisAlignment.center,
                        textDirection: TextDirection.rtl,
                        children: <Widget>[
                          Padding(
                            padding: EdgeInsets.only(top: 15, bottom: 15),
                            child: InkWell(
                                child: Text("Learn More >",
                                    style: TextStyle(fontSize: 18)),
                                onTap: () async {
                                  var url = weblink;
                                  if (await canLaunch(url)) {
                                    await launch(url, forceWebView: false);
                                  } else {
                                    throw 'Could not launch $url';
                                  }
                                }),
                          ),
                        ],
                      ),
                    ],

I / flutter(29498):引发了另一个异常:未布置RenderBox:RenderFlex#4d43f relayoutBoundary = up14 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATEI / flutter(29498):引发了另一个异常:未布置RenderBox:RenderConstrainedBox#18160 relayoutBoundary = up13 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATEI / flutter(29498):引发了另一个异常:未布置RenderBox:RenderPadding#4486e relayoutBoundary = up12 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATEI / flutter(29498):引发了另一个异常:未布置RenderBox:_RenderSingleChildViewport#b4572 relayoutBoundary = up11 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATEI / flutter(29498):引发了另一个异常:未布置RenderBox:RenderIgnorePointer#87d08 relayoutBoundary = up10 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATEI / flutter(29498):引发了另一个异常:未布置RenderBox:RenderSemanticsAnnotations#8fa89 relayoutBoundary = up9 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATEI / flutter(29498):引发了另一个异常:未布置RenderBox:RenderPointerListener#b9ffd relayoutBoundary = up8 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATEI / flutter(29498):引发了另一个异常:未布置RenderBox:RenderSemanticsGestureHandler#f3831 relayoutBoundary = up7 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATEI / flutter(29498):引发了另一个异常:未布置RenderBox:RenderPointerListener#fe472 relayoutBoundary = up6 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATEI / flutter(29498):引发了另一个异常:未布置RenderBox:_RenderScrollSemantics#6b201 relayoutBoundary = up5 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATEI / flutter(29498):引发了另一个异常:未布置RenderBox:RenderRepaintBoundary#da0f9 relayoutBoundary = up4 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATEI / flutter(29498):引发了另一个异常:未布置RenderBox:RenderCustomPaint#68715 relayoutBoundary = up3 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATEI / flutter(29498):引发了另一个异常:未布置RenderBox:RenderRepaintBoundary#b7790 relayoutBoundary = up2 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATEI / flutter(29498):引发了另一个异常:未布置RenderBox:RenderDecoratedBox#eb17f relayoutBoundary = up1 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATEI / flutter(29498):引发了另一个异常:未布置RenderBox:RenderDecoratedBox#eb17f relayoutBoundary = up1

我尝试了Expanded()小部件,那里也没有结果。有任何想法吗?谢谢!

flutter flutter-layout
1个回答
1
投票

您可以尝试一下:

Demo:

Demo ListView

代码:

Widget buildBody(BuildContext context) {
    return Column(
      children: <Widget>[
        Container(
          color: Colors.pink,
          child: Row(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              Padding(
                padding: const EdgeInsets.all(16.0),
                child: Text("Image"),
              ),
            ],
          ),
        ),
        Container(
          color: Colors.orangeAccent,
          child: Row(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              Padding(
                padding: const EdgeInsets.all(16.0),
                child: Text("Text"),
              ),
            ],
          ),
        ),
        Expanded(
          child: _buildListView(),
        ),
        Container(
          color: Colors.cyanAccent,
          child: Row(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              Padding(
                padding: const EdgeInsets.all(16.0),
                child: Text("Bottom 1"),
              ),
              Padding(
                padding: const EdgeInsets.all(16.0),
                child: Text("Bottom 2"),
              ),
            ],
          ),
        )
      ],
    );
  }

  Widget _buildListView() {
    return ListView.separated(
      itemCount: 1000,
      itemBuilder: (context, index) {
        return Padding(
          padding: const EdgeInsets.all(16.0),
          child: Center(child: Text("Item ${index + 1}")),
        );
      },
      separatorBuilder: (context, index) {
        return Divider(
          height: 1,
        );
      },
    );
  }
© www.soinside.com 2019 - 2024. All rights reserved.