首页 文章

Flutter ListView收缩包装 - 嵌套ListView

提问于
浏览
1

我在ListView中有一个ListView,内部ListView不知道它应该是多高,所以我必须给它一个特定的高度,比如一个SizedBox . 然而问题是我实际上希望内部ListView缩小换行,以便它不会在父ListView中滚动/占用不必要的空间 .

提前致谢

1 回答

  • 7

    这听起来像CustomScrollView的一个很好的用例 .

    video

    import 'dart:async';
    import 'package:flutter/material.dart';
    
    void main() {
      runApp(new MaterialApp(
        home: new Scaffold(
          body: new CustomScrollView(
            slivers: [
              new SliverToBoxAdapter(
                child: new Container(height: 100.0, color: Colors.blueAccent),
              ),
              new SliverList(
                delegate: new SliverChildListDelegate(
                  new List<Widget>.generate(10, (int index) {
                    return new Text(
                      'Item $index',
                      style: new TextStyle(fontSize: 42.0),
                    );
                  }),
                ),
              ),
              new SliverToBoxAdapter(
                child: new Container(height: 100.0, color: Colors.tealAccent),
              ),
            ],
          ),
        ),
      ));
    }
    

相关问题