当物理设置为NeverScrollableScrollPhysics时,将切断ListView Builder项目

时间:2019-01-04 06:35:48

标签: listview flutter

我有一个GridView生成器,里面有一个ListViewgridView有两个childs 1.标头文本和2。ListView 标题文本包括本科生和PostGraduateListView代表本科生包括10个项目,而ListView代表研究生生包括3个项目。

但是即使我将ListView包装在扩展小部件中,我在本科生ListView中也只能看到4个项目。

我不想使子级listview滚动。我已经将内部ListView包裹在Expandable中,但仍未显示所有项目

以下是我的代码

return GridView.builder(
      gridDelegate:
          SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 2),
      shrinkWrap: true,
      itemBuilder: (context, index) {
        return Column(
          crossAxisAlignment: CrossAxisAlignment.stretch,
          children: <Widget>[
            Container(
              decoration: BoxDecoration(color: Colors.black),
              padding: EdgeInsets.fromLTRB(20.0, 4.0, 20.0, 4.0),
              margin: EdgeInsets.fromLTRB(8.0, 8.0, 8.0, 0.0),
              child: Text(
                "${disciplineModelDataList[index].disciplineName}",
                textAlign: TextAlign.center,
                style: TextStyle(
                    color: Colors.white, fontFamily: "suisseintlMedium"),
              ),
            ),
            Expanded(
              child: Container(
                margin: EdgeInsets.symmetric(horizontal: 8.0),
                child: ListView.separated(
                    shrinkWrap: true,
                    separatorBuilder: (BuildContext context, int index) =>
                        Divider(
                          height: 0.2,
                        ),
                    physics: NeverScrollableScrollPhysics(),
                    itemCount: disciplineModelDataList[index].years.length,
                    itemBuilder: (BuildContext context3, int index3) {
                      return Card(
                        color: Colors.lightGreen,
                        margin: EdgeInsets.all(0.0),
                        child: Padding(
                          padding: const EdgeInsets.symmetric(vertical: 8.0),
                          child: InkWell(
                            onTap: () {
                              print(index.toString());
                            },
                            child: Row(
                              children: <Widget>[
                                Expanded(
                                  child: Text(
                                    "${disciplineModelDataList[index].years[index3].yearName}",
                                    textAlign: TextAlign.center,
                                    style: TextStyle(
                                        fontFamily: "okomitoBold",
                                        color: Colors.black),
                                  ),
                                ),
                                Icon(Icons.arrow_forward)
                              ],
                            ),
                          ),
                        ),
                      );
                    }),
              ),
            )
          ],
        );
      },
      itemCount: disciplineModelDataList.length,
    );

1 个答案:

答案 0 :(得分:0)

您不应在GridView中使用ListView。改用Column

return GridView.builder(
  gridDelegate:
      SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 2),
  shrinkWrap: true,
  itemBuilder: (context, index) {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.stretch,
      children: <Widget>[
        Container(
          decoration: BoxDecoration(color: Colors.black),
          padding: EdgeInsets.fromLTRB(20.0, 4.0, 20.0, 4.0),
          margin: EdgeInsets.fromLTRB(8.0, 8.0, 8.0, 0.0),
          child: Text(
            "${disciplineModelDataList[index].disciplineName}",
            textAlign: TextAlign.center,
            style: TextStyle(
                color: Colors.white, fontFamily: "suisseintlMedium"),
          ),
        ),
        Container(
          margin: EdgeInsets.symmetric(horizontal: 8.0),
          child: Column(
              children: List<Widget>.generate(disciplineModelDataList[index].years.length, (int index3) {
                return Card(
                  color: Colors.lightGreen,
                  margin: EdgeInsets.all(0.0),
                  child: Padding(
                    padding: const EdgeInsets.symmetric(vertical: 8.0),
                    child: InkWell(
                      onTap: () {
                        print(index.toString());
                      },
                      child: Row(
                        children: <Widget>[
                          Expanded(
                            child: Text(
                              "${disciplineModelDataList[index].years[index3].yearName}",
                              textAlign: TextAlign.center,
                              style: TextStyle(
                                  fontFamily: "okomitoBold",
                                  color: Colors.black),
                            ),
                          ),
                          Icon(Icons.arrow_forward)
                        ],
                      ),
                    ),
                  ),
                );
              },),),
        )
      ],
    );
  },
  itemCount: disciplineModelDataList.length,
);