颤抖-在列表视图构建器中滚动列表视图

时间:2018-11-05 02:08:07

标签: list listview dart flutter

我有一个“过滤器”,下面是足球比赛的列表。我用ListView包装“ Filter and” listview builder”(这样就解决了blablabla下的重载问题)。但是,当您正常滚动时,会有一些奇怪的事情。滚动到无效的列表。只有一个“发光效果”,但是我从上面的“过滤器菜单”滚动,该滚动有效。如何使滚动正常运行?

see image

我的代码片段:

Widget _buildListView(FixtureModel model, BuildContext context) {
    return Container(
        child: model.getFixturesCount() == 0
            ? Center(child: Text('No fixtures found'))
            : ListView(
                shrinkWrap: true,
                children: <Widget>[
                  Column(
                    children: <Widget>[
                      Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: <Widget>[
                          Container(
                              padding: EdgeInsets.only(left: 10.0),
                              child: InkWell(
                                onTap: () => _onTap(context),
                                child: Container(
                                    margin:
                                        EdgeInsets.only(top: 5.0, bottom: 5.0),
                                    child: Row(
                                      children: <Widget>[
                                        Container(
                                            padding: EdgeInsets.only(left: 5.0),
                                            child:
                                                Icon(FontAwesomeIcons.github)),
                                        Container(
                                          padding: EdgeInsets.only(left: 15.0),
                                          child: Text(
                                            'Liga Premier Inggris',
                                            style: TextStyle(
                                                fontSize: 16.0,
                                                fontWeight: FontWeight.w500),
                                          ),
                                        ),
                                        Container(
                                            padding: EdgeInsets.only(
                                                left: 5.0, top: 2.0),
                                            child: Icon(Icons.arrow_drop_down,
                                                size: 17.0))
                                      ],
                                    )),
                              )),
                          Container(
                            padding: EdgeInsets.only(top: 3.0),
                            child: Text(
                              '4',
                              style:
                                  TextStyle(fontSize: 13.0, color: Colors.grey),
                            ),
                          ),
                          IconButton(
                              iconSize: 20.0,
                              icon: Icon(
                                FontAwesomeIcons.calendarAlt,
                                color: Colors.blue,
                              ),
                              onPressed: () {})
                        ],
                      ),
                      Divider(
                        height: 0.0,
                      ),
                      Container(
                          padding: EdgeInsets.only(top: 2.0),
                          child: ListView.builder(
                            shrinkWrap: true,
                            itemCount: model.fixtureList == null
                                ? 0
                                : model.getFixturesCount(),
                            itemBuilder: (context, int i) {
                              var fixture = model.fixtureList[i];

                              return FixtureListItem(fixture: fixture);
                            },
                          ))
                    ],
                  )
                ],
              ));
  }

1 个答案:

答案 0 :(得分:4)

在您的ListView中添加:

shrinkWrap: true,
physics: NeverScrollableScrollPhysics(),

要从ListView中取出过滤器:remove physics: NeverScrollableScrollPhysics(), then in ListView

body: Column(
                  children: <Widget>[
                     Filter(),
                     Expanded(
                        child: ListView()
                     ),
                ]
            )