Flutter ListView收缩包装 - 嵌套ListView

The*_*man 3 dart flutter

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

提前致谢

Col*_*son 13

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

视频

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),
          ),
        ],
      ),
    ),
  ));
}
Run Code Online (Sandbox Code Playgroud)