【问题标题】:How to create overlapping sliverlist container in flutter如何在颤动中创建重叠的 sliverlist 容器
【发布时间】:2021-05-13 04:38:00
【问题描述】:

我需要在容器下方与 sliverappbar 重叠的附加图像之类的东西。有什么帮助吗?

https://i.stack.imgur.com/JY1iH.jpg

【问题讨论】:

    标签: flutter flutter-layout


    【解决方案1】:

    这和你的情况很相似,SliverAppBar,你可以尝试修改中间部分的位置:

    class Sample2 extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return SafeArea(
          child: Material(
            child: CustomScrollView(
              slivers: [
                SliverPersistentHeader(
                  delegate: MySliverAppBar(expandedHeight: 200),
                  pinned: true,
                ),
                SliverList(
                  delegate: SliverChildBuilderDelegate(
                    (_, index) => ListTile(
                          title: Text("Index: $index"),
                        ),
                  ),
                )
              ],
            ),
          ),
        );
      }
    }
    
    class MySliverAppBar extends SliverPersistentHeaderDelegate {
      final double expandedHeight;
    
      MySliverAppBar({@required this.expandedHeight});
    
      @override
      Widget build(
          BuildContext context, double shrinkOffset, bool overlapsContent) {
        return Stack(
          fit: StackFit.expand,
          overflow: Overflow.visible,
          children: [
            Image.network(
              "https://images.pexels.com/photos/396547/pexels-photo-396547.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500",
              fit: BoxFit.cover,
            ),
            Center(
              child: Opacity(
                opacity: shrinkOffset / expandedHeight,
                child: Text(
                  "MySliverAppBar",
                  style: TextStyle(
                    color: Colors.white,
                    fontWeight: FontWeight.w700,
                    fontSize: 23,
                  ),
                ),
              ),
            ),
            Positioned(
              top: expandedHeight / 2 - shrinkOffset,
              left: MediaQuery.of(context).size.width / 4,
              child: Opacity(
                opacity: (1 - shrinkOffset / expandedHeight),
                child: Card(
                  elevation: 10,
                  child: SizedBox(
                    height: expandedHeight,
                    width: MediaQuery.of(context).size.width / 2,
                    child: FlutterLogo(),
                  ),
                ),
              ),
            ),
          ],
        );
      }
    
      @override
      double get maxExtent => expandedHeight;
    
      @override
      double get minExtent => kToolbarHeight;
    
      @override
      bool shouldRebuild(SliverPersistentHeaderDelegate oldDelegate) => true;
    }
    

    【讨论】:

      猜你喜欢
      • 2020-03-01
      • 2019-07-18
      • 2020-07-10
      • 1970-01-01
      • 1970-01-01
      • 2021-03-03
      • 2021-01-22
      • 1970-01-01
      • 2021-05-10
      相关资源
      最近更新 更多