带有柔性卡列的SingleChildScrollView:“ RenderFlex在底部被x像素溢出”,如何使卡扩展?

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

我正在尝试列出在SingleChildScrollView中显示的卡片列表。但是我不知道如何使卡片适合其内容。

我附上我的问题的照片,以及我希望卡片的外观。

我已经尝试将它们放在似乎没有什么不同的扩展中。

我也尝试过在卡容器上设置手动高度,由于某种原因,它只能显示两张卡,而不能让我滚动。

我想我需要在卡片上设置最小高度,但是我似乎无法弄清楚应该在哪个高度上添加它。

Widget displayVideo(item) {
    return Flexible(
      child: Container(
        child: Card(
          child: Column(
            children: <Widget>[
              ListTile(
                leading: CircleAvatar(
                  backgroundImage:
                      NetworkImage(item.fromChannel.channelThumbnail),
                ),
                title: Text(item.fromChannel.channelTitle),
                subtitle: Text(item.publishAt),
              ),
              Container(
                child: new AspectRatio(
                  aspectRatio: 16 / 10,
                  child: new Container(
                    decoration: new BoxDecoration(
                        image: new DecorationImage(
                      fit: BoxFit.fitWidth,
                      alignment: FractionalOffset.center,
                      image: new NetworkImage(item.thumbnailUrl),
                    )),
                  ),
                ),
              ),
              Container(
                child: Padding(
                  padding: const EdgeInsets.all(8.0),
                  child: Text(
                    item.title,
                    style: TextStyle(color: Colors.black, fontSize: 16),
                  ),
                ),
              )
            ],
          ),
        ),
      ),
    );
  }

  Widget displayVideos(items) {
    List<Widget> lines = [];
    print(items);
    items.videos.forEach((element) => lines.add(displayVideo(element)));

    return SingleChildScrollView(
        child: Container(
            height: MediaQuery.of(context).size.height,
            child: Column(children: lines)));
  }

  @override
  Widget build(BuildContext context) {
    final ExplorePlaylistArguments args =
        ModalRoute.of(context).settings.arguments;
    playlist = fetchPlaylist(args.playlistId);
    return Scaffold(
        appBar: AppBar(
          title: Text(args.playlistName),
        ),
        body: Container(
          child: FutureBuilder<Playlist>(
              future: playlist,
              builder: (context, snapshot) {
                if (snapshot.hasData) {
                  return displayVideos(snapshot.data);
                } else if (snapshot.hasError) {
                  return Text("${snapshot.error}");
                }
                // By default, show a loading spinner.
                return Center(child: CircularProgressIndicator());
              }),
        ));
  }

════════ Exception caught by rendering library ═════════════════════════════════════════════════════
The following assertion was thrown during layout:
A RenderFlex overflowed by 303 pixels on the bottom.

The relevant error-causing widget was: 
  Column file:///C:/Users/Jonathan/AndroidStudioProjects/klp_app/lib/screens/explore_playlist.dart:29:18
The overflowing RenderFlex has an orientation of Axis.vertical.
The edge of the RenderFlex that is overflowing has been marked in the rendering with a yellow and black striped pattern. This is usually caused by the contents being too big for the RenderFlex.

Consider applying a flex factor (e.g. using an Expanded widget) to force the children of the RenderFlex to fit within the available space instead of being sized to their natural size.
This is considered an error condition because it indicates that there is content that cannot be seen. If the content is legitimately bigger than the available space, consider clipping it with a ClipRect widget before putting it in the flex, or using a scrollable container rather than a Flex, like a ListView.

The specific RenderFlex in question is: RenderFlex#42b06 relayoutBoundary=up19 OVERFLOWING
...  parentData: <none> (can use size)
...  constraints: BoxConstraints(0.0<=w<=384.7, 0.0<=h<=67.9)
...  size: Size(384.7, 67.9)
...  direction: vertical
...  mainAxisAlignment: start
...  mainAxisSize: max
...  crossAxisAlignment: center
...  verticalDirection: down
◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤
════════════════════════════════════════════════════════════════════════════════════════════════════

════════ Exception caught by rendering library ═════════════════════════════════════════════════════
A RenderFlex overflowed by 303 pixels on the bottom.

卡的外观:

How it's looks like

我希望每张卡的外观如何:

How I want the cards to look like

flutter flutter-layout
1个回答
0
投票

您必须从displayVideos方法中删除容器

return SingleChildScrollView(child: Column(children: lines)); // container remove

删除弹性]从displayVideo方法

© www.soinside.com 2019 - 2024. All rights reserved.