小编Gan*_*uan的帖子

在Flutter中,如何创建磨砂玻璃效果的SliverAppBar?

我想创建一个类似于 Apple News 应用程序中的顶部应用程序栏。

在屏幕截图中看到模糊有点困难,因为条形图太细了,但你明白了。

截屏

我希望该栏通过滚动来展开和收缩,并在收缩时固定在顶部,就像屏幕截图中一样,SliverAppBar 可以完成所有这些操作,只是我无法将其包裹在 ClipRect、BackdropFilter 和 Opacity 中以创建磨砂玻璃效果是因为 CustomScrollView 仅采用 RenderSliv​​er 子类。

我的测试代码:

Widget build(BuildContext context) {
  return CustomScrollView(
    slivers: <Widget>[
      SliverAppBar(
        title: Text('SliverAppBar'),
        elevation: 0,
        floating: true,
        pinned: true,
        backgroundColor: Colors.grey[50],
        expandedHeight: 200.0,
        flexibleSpace: FlexibleSpaceBar(
            background: Image.network("https://i.imgur.com/cFzxleh.jpg", fit: BoxFit.cover)
        ),
      )
      ,
      SliverFixedExtentList(
        itemExtent: 150.0,
        delegate: SliverChildListDelegate(
          [
            Container(color: Colors.red),
            Container(color: Colors.purple),
            Container(color: Colors.green),
            Container(color: Colors.orange),
            Container(color: Colors.yellow),
            Container(color: Colors.pink,
              child: Image.network("https://i.imgur.com/cFzxleh.jpg", fit: BoxFit.cover)
            ),
          ],
        ),
      ),
    ],
  );
}
Run Code Online (Sandbox Code Playgroud)

有办法实现我想要的吗?

flutter flutter-sliver

3
推荐指数
1
解决办法
3787
查看次数

标签 统计

flutter ×1

flutter-sliver ×1