【问题标题】:Flutter ; Vertical ListView inside a column(inside another column) causing an overflow颤振;列内(另一列内)的垂直 ListView 导致溢出
【发布时间】:2023-01-07 00:38:49
【问题描述】:
class Episodes extends StatefulWidget {
  const Episodes({super.key});

  @override
  State<Episodes> createState() => _EpisodesState();
}

class _EpisodesState extends State<Episodes> {
  final seasons = ['Season 1', 'Season 2', 'Season 3'];

  String? value;
  @override
  Widget build(BuildContext context) {
    Size size = MediaQuery.of(context).size;
    //EdgeInsets.only(left: size.width * 0.03, right: size.width * 0.03),
    return SingleChildScrollView(
      physics: const AlwaysScrollableScrollPhysics(),
      child: Column(
        children: [
          Container(
            height: size.height * 0.045,
            width: size.width * 0.25,
            decoration: BoxDecoration(
                color: Colors.grey.withOpacity(0.25),
                borderRadius: BorderRadius.circular(5)),
            child: DropdownButtonHideUnderline(
              child: DropdownButton<String>(
                value: value,
                alignment: Alignment.center,
                isExpanded: true,
                //icon: Icon(Icons.arrow_drop_down_outlined,
                //  size: 12, color: Colors.white),
                iconEnabledColor: Colors.white,

                //dropdownColor: Colors.transparent,
                items: seasons.map(buildMenuItem).toList(),
                dropdownColor: Colors.grey.withOpacity(0.3),
                onChanged: (value) => setState(() {
                  this.value = value;
                }),
              ),
            ),
          ),
          SizedBox(height: size.height * 0.02),
          ListView.builder(
            shrinkWrap: true,
            //physics: const AlwaysScrollableScrollPhysics(),
            itemCount: 15,
            scrollDirection: Axis.vertical,
            itemBuilder: (context, index) {
              return Padding(
                padding: const EdgeInsets.only(bottom: 8),
                child: Container(
                  color: Colors.red,
                  height: 15,
                  width: 15,
                ),
              );
            },
          ),
        ],
      ),
    );
  }

  DropdownMenuItem<String> buildMenuItem(String item) => DropdownMenuItem(
      value: item,
      child: Center(
        child: Text(
          item,
          style: GoogleFonts.poppins(color: Colors.white, fontSize: 12),
        ),
      ));
}

我正在尝试构建一个 netflix 克隆,这是标题页中剧集列表的设计。 基本上,我试图在列中包含 listview.builder(vertical);但我收到溢出错误。 此列进一步作为另一个文件中父列的子列之一返回。

到目前为止,我已经尝试将列包装在以下位置: *单子滚动视图, *展开 *SizedBox, Container : 固定高度

以上均无效;我什至尝试玩弄滚动物理,但没有用,溢出错误仍然存​​在。

我是新来的;我只想摆脱溢出错误。任何帮助将不胜感激! 此外,我希望从 firebase 动态获取详细信息并在此处显示它们。对此的任何提示也将不胜感激!

【问题讨论】:

  • 它正在工作,你能包括更多关于它的父部件的信息吗

标签: flutter listview overflow singlechildscrollview


【解决方案1】:

据我了解,您在主页上有类似的内容:

Column(children : [
  SomeWidget(),
  OtherWidget(),
  Episodes(),
]);

由于 Episodes() 在 Column 中,它被赋予了无限的高度。如果您希望它获得页面的剩余高度,您应该将它包装在一个 Expanded() 小部件中,如下所示。

Column(children : [
  SomeWidget(),
  OtherWidget(),
  Expanded(child:Episodes()),
]);

如果这不能解决您的问题,请提供有关父小部件(使用剧集的地方)的更多信息。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-09-30
    • 1970-01-01
    • 2020-11-05
    • 2018-11-17
    • 2020-11-13
    • 2019-05-19
    • 2015-08-26
    • 2021-08-11
    相关资源
    最近更新 更多