Flutter - 在Listview Builder中滚动列表视图

4
我有一个“筛选器”,下面是一系列足球比赛。我用ListView包装“Filter”和“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);
                            },
                          ))
                    ],
                  )
                ],
              ));
  }

在你的ListView中添加 shrinkWrap: true, physics: NeverScrollableScrollPhysics()。 - anmol.majhail
是的,您需要使选项卡栏数据持久化 - 用于 - DetailMatchTab(widget.fixture) 类使用 AutomaticKeepAliveClientMixin,评论文章提供了很好的示例 - https://medium.com/@diegoveloper/flutter-persistent-tab-bars-a26220d322bc - anmol.majhail
_DetailMatchTabState 类继承自 State<DetailMatchTab>,同时混入了 AutomaticKeepAliveClientMixin<DetailMatchTab>。 - anmol.majhail
好的,Before - 返回ScopedModelDescendant添加 - super.build(context); - anmol.majhail
嗯,我找到了。在添加新数据之前,我声明了List <Standings> = []。感谢您的时间,@anmol.majhail先生。 - Muhammad Imanudin
显示剩余4条评论
1个回答

26
在您的ListView中添加:

shrinkWrap: true,
physics: NeverScrollableScrollPhysics(),
从ListView中移除过滤器:移除 physics: NeverScrollableScrollPhysics(),然后在ListView中
body: Column(
                  children: <Widget>[
                     Filter(),
                     Expanded(
                        child: ListView()
                     ),
                ]
            )

哇...太酷了,谢谢你的帮助。还有一个问题,是否可能让“筛选器”直立,然后当滚动时只是移动列表? - Muhammad Imanudin
1
将筛选器从ListView中移出,在第一列放置Widget - 筛选器,第二个是Listview。 主体:Column 子项:<Widget>[Filter(),Expanded (ListView())]。我已更新答案并附上代码。 - anmol.majhail
@Muhammad - 我现在不在,稍后会检查。 - anmol.majhail
@MuhammadImanudin - 我并没有深入研究过Slivers - 无法提供帮助,但您可以查看 - https://docs.flutter.io/flutter/widgets/SliverOverlapInjector-class.html和https://github.com/flutter/flutter/issues/22393 - anmol.majhail
1
我把它变成了透明的,并进行了一些布局,使其看起来像叠在sliverlist和sliverappbar上。谢谢您,先生。 - Muhammad Imanudin
显示剩余2条评论

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接