首页 > 解决方案 > Flutter:当我滚动到 NESTED ListView 的末尾时,我希望父 ListView 滚动

问题描述

以下代码实现了一个带有嵌套 ListView 作为子级之一的 ListView。

Web 构建的行为:当我向下滚动到嵌套 ListView 的底部时,它会导致父级滚动。

Android 构建的行为:当我向下滚动到嵌套 ListView 的底部时,它不会导致父级滚动。

为什么有区别?如何使 Android 构建的行为类似于 Web 构建?

谢谢

import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(title: Text('Demo')),
        // body: CollapsingList(),
        body: NestedLists(),
      ),
    );
  }
}

class NestedLists extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return ListView(
      children: [
        Container(color: Colors.red, height: 150.0),
        Container(color: Colors.purple, height: 150.0),
        Container(color: Colors.green, height: 150.0),
        Container(color: Colors.orange, height: 150.0),
        Padding(
          padding: const EdgeInsets.all(20.0),
          child: Container(
            height: 150,
            child: ListView(
              children: [
                Container(color: Colors.yellow, height: 50.0),
                Container(color: Colors.pink, height: 50.0),
                Container(color: Colors.cyan, height: 50.0),
                Container(color: Colors.indigo, height: 50.0),
                Container(color: Colors.blue, height: 50.0),
                Container(color: Colors.yellow, height: 50.0),
                Container(color: Colors.pink, height: 50.0),
                Container(color: Colors.cyan, height: 50.0),
                Container(color: Colors.indigo, height: 50.0),
                Container(color: Colors.blue, height: 50.0),
                Container(color: Colors.yellow, height: 50.0),
              ],
            ),
          ),
        ),
        Container(color: Colors.yellow, height: 150.0),
        Container(color: Colors.pink, height: 150.0),
        Container(color: Colors.cyan, height: 150.0),
        Container(color: Colors.indigo, height: 150.0),
        Container(color: Colors.blue, height: 150.0),
      ],
    );
  }
}

标签: androidflutterlistview

解决方案


推荐阅读