簡體   English   中英

Flutter中如何實現嵌套條子

[英]How to achieve nested slivers in Flutter

我想在 Flutter 中實現以下功能:

CustomScrollView(
  slivers: [
    NestedSlivers(
      slivers: [
         SliverOutside(
           child: SliverInside()
         )
      ])
   ]
)

目前我正在使用帶有 ShrinkWrappingViewport 的 Slivers,但它的性能非常糟糕。 所以任何幫助或線索都會非常有用。 非常感謝!

您可以使用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('App Bar'),
            ),
          ];
        },
        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 No. $index');
                },
              ),
            ),
            new FlutterLogo(size: 50.0, colors: Colors.red),
          ],
        ),
      ),
    );
  }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM