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

Flutter移动端ListView滚动异常:Web端正常但Android端失效

解决Flutter ListView在Android端无法滚动的问题

问题诊断

你的代码存在嵌套ListView结构:外层ListView包裹标题与内层ListView.builder。尽管内层ListView设置了shrinkWrap: true,但在Android设备上,触摸滚动事件会被外层ListView拦截,导致内层列表无法响应滚动;同时你使用的是7个月前的Flutter Dev Channel旧版本(3.4.0-17.2.pre),该版本可能存在Android滚动相关的已知bug,进一步加剧了问题。

解决方案

方案1:移除嵌套ListView,改用SingleChildScrollView

直接用SingleChildScrollView包裹整个内容区域,避免滚动容器嵌套冲突,这是最简洁的修复方式:

修改后的核心代码:

@override
Widget build(BuildContext context) {
  return FutureBuilder<List<Genre>>(
    future: genreProvider.getAllGenres(),
    builder: (context, snapshot) {
      if (snapshot.hasData) {
        final genres = snapshot.data;
        return Scaffold(
          key: scaffoldKey,
          backgroundColor: Color(0xFFF1F4F8),
          appBar: AppBar(
            // 保留原AppBar代码不变
            backgroundColor: Color(0xFFB4FFA8),
            automaticallyImplyLeading: false,
            actions: [
              FlutterFlowIconButton(
                borderColor: Colors.transparent,
                borderRadius: 30.0,
                borderWidth: 1.0,
                buttonSize: 60.0,
                icon: Icon(
                  Icons.person,
                  color: Colors.black,
                  size: 30.0,
                ),
                onPressed: () async {
                  await Navigator.push(
                    context,
                    MaterialPageRoute(
                      builder: (context) => UserConfigWidget(),
                    ),
                  );
                },
              ),
            ],
            centerTitle: true,
            toolbarHeight: 100.0,
            elevation: 4.0,
          ),
          body: SingleChildScrollView( // 替换外层ListView为SingleChildScrollView
            padding: EdgeInsets.zero,
            child: Column(
              mainAxisSize: MainAxisSize.min, // 让Column自适应内容高度
              children: [
                Padding(
                  padding: EdgeInsetsDirectional.fromSTEB(10.0, 10.0, 10.0, 10.0),
                  child: Text(
                    'Title',
                    style: FlutterFlowTheme.of(context)
                        .bodyText1
                        .override(
                          fontFamily: 'Poppins',
                          color: FlutterFlowTheme.of(context).black600,
                          fontSize: 25.0,
                        ),
                  ),
                ),
                genres == null
                    ? Center(child: Text('No genres found'))
                    : ListView.builder(
                        shrinkWrap: true,
                        physics: NeverScrollableScrollPhysics(), // 禁止内层列表处理滚动
                        itemCount: genres.length,
                        itemBuilder: (BuildContext context, int index) {
                          return GenreCard(genre: genres[index]);
                        },
                      ),
              ],
            ),
          ),
        );
      }
      // 保留加载状态代码不变
      return Center(
        child: SizedBox(
          width: 48.0,
          height: 48.0,
          child: CircularProgressIndicator(
            valueColor: AlwaysStoppedAnimation<Color>(Colors.green),
          ),
        ),
      );
    },
  );
}

方案2:升级Flutter到稳定版

你当前使用的Dev Channel版本存在较多未修复的bug,建议切换到Stable Channel:

flutter channel stable
flutter upgrade

关键修改说明

  • 用SingleChildScrollView替代外层ListView,让整个页面作为单一滚动容器,避免事件拦截。
  • 给内层ListView.builder添加physics: NeverScrollableScrollPhysics(),确保滚动事件完全由外层容器处理。
  • 将外层Column的mainAxisSize设为MainAxisSize.min,避免布局溢出问题。

内容的提问来源于stack exchange,提问作者Albert Pineda Basalobre

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.24 20:04:53