【问题标题】:Flutter ListView shrink wrap - nested ListViewFlutter ListView 收缩包装 - 嵌套 ListView
【发布时间】:2017-08-19 17:06:22
【问题描述】:

我在 ListView 中有一个 ListView,而内部 ListView 不知道它应该有多高,所以我必须给它一个特定的高度,例如一个 SizedBox。但是问题是我实际上希望内部 ListView 收缩包装,这样它就不会在父 ListView 中滚动/占用不必要的空间。

提前致谢

【问题讨论】:

  • 我对您的问题有点困惑,您是否尝试将 shrinkWrap 属性设置为 true ?
  • 也许使用 Column 而不是嵌套的 ListView?

标签: dart flutter


【解决方案1】:

这听起来像是 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),
          ),
        ],
      ),
    ),
  ));
}

【讨论】:

    猜你喜欢
    • 2021-05-19
    • 2023-04-08
    • 1970-01-01
    • 2019-01-17
    • 1970-01-01
    • 2017-12-29
    • 1970-01-01
    • 2018-07-05
    • 2020-02-13
    相关资源
    最近更新 更多