【问题标题】:How to have a nested SliverList in Flutter?如何在 Flutter 中有一个嵌套的 SliverList?
【发布时间】:2021-06-02 04:48:57
【问题描述】:

我在 CustomScrollView 中使用 SliverAppBar 和 SliverList。现在我想在我拥有的 SliverList 中构建另一个 ListView。但它不让我。

【问题讨论】:

标签: flutter flutter-web flutter-sliver


【解决方案1】:

您需要NestedScrollView

这是一个例子:-

class MyHomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new Scaffold(
     appBar: SliverAppBar(),
      body: new NestedScrollView(
        headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
          return <Widget>[
            new SliverAppBar(
              pinned: true,
              title: new Text('Flutter Demo'),
            ),
          ];
        },
        body: new Column(
          children: <Widget>[
            new FlutterLogo(size: 100.0, colors: Colors.purple),
            new Container(
              height: 300.0,
              child: new ListView.builder(
                itemCount: 60,
                itemBuilder: (BuildContext context, int index) {
                  return new Text('Item $index');
                },
              ),
            ),
            new FlutterLogo(size: 100.0, colors: Colors.orange),
          ],
        ),
      ),
    );
  }
}

【讨论】:

    猜你喜欢
    • 2023-04-08
    • 2020-10-02
    • 2021-10-14
    • 1970-01-01
    • 2019-12-10
    • 2020-07-03
    • 2020-07-10
    • 2021-02-14
    • 1970-01-01
    相关资源
    最近更新 更多