-2

如何在具有嵌套小部件的列上实现 SingleChildScrollView?
代码片段导致抛出错误,在这里帮助一个颤抖的新手!

在下面的小部件中,我试图将其内容包装在可滚动容器中,在实现 SingleChildScrollView 示例时,RenderFlex 子项具有非零弹性,但传入的高度约束是无界的。产生错误。我已经测试了在列中嵌套子小部件,但只有 sizedbox 选项有效,但这将大小限制在预定高度,对于各种设置可能不同。

小部件 getVideoBody() {

int _index = 0;
return Scaffold(
  backgroundColor: Colors.black54,
  appBar: AppBar(
    backgroundColor: Color(0xff000000),
    title: Text(
      'GooGGle',
    ),
  ),
  body: Align(alignment: Alignment.topCenter,
    child: SingleChildScrollView(
      child: Column(mainAxisSize: MainAxisSize.min,
        children: [
          ConstrainedBox(
            constraints: BoxConstraints(maxHeight: 290, minHeight: 200.0),
            //height: 285, // card height
            //width: 400,
            child: PageView.builder(
              itemCount: videObj.results.length,
              controller: PageController(viewportFraction: 0.7),
              //onPageChanged: (int index) => setState(() => _index = index),
              itemBuilder: (_, i) {
                String vidKey = videObj.results[i].key;
                String thumbPath = VideoDetails.thumbURL.replaceAll('xxxxxx', vidKey);
                String videoPath = VideoDetails.videoURL + vidKey;

                return Transform.scale(
                  scale: i == _index ? 1 : 0.9,
               
                  child: new InkWell(
                    //onFocusChange: (hasFocus){ _index++;},
                    onTap: (){
                      videoPath;
                      print(videoPath);
                           Uri.parse(
                          videoPath);
                    },
                    child: Card(
                      clipBehavior: Clip.antiAlias,
                      child: Column(
                        children: [
                          Image.network(
                            thumbPath,
                            fit: BoxFit.cover,
                          ),
                          ListTile(
                            title: Text(videObj.results[i].name),
                          ),
                        ],
                      ),
                    ),
                  ),
                );
              },
            ),
          ),
          Container(
            child: Container(
              child: Container(
                color: const Color(0xff000000), // Red
                height: 20.0,
                alignment: Alignment.topLeft,
                padding: EdgeInsets.all(30.0),
                child: Text(widget.movieDets.title,
                    textAlign: TextAlign.justify,
                    style: const TextStyle(
                        fontWeight: FontWeight.bold,
                        fontSize: 25.0,
                        color: Colors.white70)

                ),
              ),
          //  ),
          ),
          Spacer(),
          Text('Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse semper iaculis elit accumsan lacinia. Nullam non sem non elit sagittis vestibulum id a eros. Proin vitae magna rutrum, hendrerit est nec, aliquam magna. Proin lobortis iaculis felis nec tempus. Nam a consequat ante. Aliquam eu arcu nec velit varius rutrum ac a nisl. Quisque id augue iaculis, convallis massa ut, pretium elit. Suspendisse fringilla ipsum erat, quis feugiat lorem dictum quis. Nullam et iaculis orci, sit amet auctor augue.', style: const TextStyle(
              fontWeight: FontWeight.bold,
              fontSize: 25.0,
              color: Colors.white70),),

        ],
      ),
    ),
  ),
);

}

4

1 回答 1

1

因为Column没有固定的高度.. 当您Spacer()在列内部使用时..Spacer()将扩展以填充剩余的空间..在这种情况下它将是无限的给你一个错误..

所以要么删除Spacer()小部件,要么给列一个高度

于 2021-07-01T16:12:13.197 回答