You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flutter中PageView内卡片列表无法垂直滚动问题

Flutter PageView内ListView无法垂直滚动的解决方法

你的问题根源很明确:每个ListView.builder都设置了physics: NeverScrollableScrollPhysics(),这个配置直接禁用了ListView的垂直滚动功能,所以才没法在单个PageView页面内滚动卡片列表。

ListView本身就是自带垂直滚动能力的组件,完全不需要额外套SingleChildScrollView,反而多套会引发滚动冲突。只需要把所有ListView里的physics: NeverScrollableScrollPhysics()这一行删掉即可,修改后的代码如下:

PageView(
  controller: swipeController,
  children: [
    //Conditions Cards for sun/clouds and rain probability
    Consumer<Settings>(
      builder: (context, weatherList, child) {
        return ListView.builder(
          // 移除NeverScrollableScrollPhysics(),恢复默认滚动行为
          itemCount: weatherList.weatherLocations.length,
          itemBuilder: (context, index) {
            return WeatherCard(
              lat: weatherList.weatherLocations[index].lat,
              long: weatherList.weatherLocations[index].lng,
              name: weatherList.weatherLocations[index].formattedAddress,
              forcastType: 'conditions',
              lastUpdate: weatherList.weatherLocations[index].lastUpdate,
            );
          },
        );
      },
    ),
    // Temperature Cards
    Consumer<Settings>(
      builder: (context, weatherList, child) {
        return ListView.builder(
          itemCount: weatherList.weatherLocations.length,
          itemBuilder: (context, index) {
            return WeatherCard(
              lat: weatherList.weatherLocations[index].lat,
              long: weatherList.weatherLocations[index].lng,
              name: weatherList.weatherLocations[index].formattedAddress,
              forcastType: 'temperature',
              lastUpdate: weatherList.weatherLocations[index].lastUpdate,
            );
          },
        );
      },
    ),
    Consumer<Settings>(
      builder: (context, weatherList, child) {
        return ListView.builder(
          itemCount: weatherList.weatherLocations.length,
          itemBuilder: (context, index) {
            return WeatherCard(
              lat: weatherList.weatherLocations[index].lat,
              long: weatherList.weatherLocations[index].lng,
              name: weatherList.weatherLocations[index].formattedAddress,
              forcastType: 'windSpeed',
              lastUpdate: weatherList.weatherLocations[index].lastUpdate,
            );
          },
        );
      },
    ),
  ],
),

修改后,PageView负责水平滑动切换不同页面,每个页面内的ListView负责垂直滚动卡片列表,两者滚动方向不同,不会产生冲突,就能实现你想要的效果了。

内容的提问来源于stack exchange,提问作者Ten Digit Grid

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.03 12:48:32