Flutter кой SliverAppBar + flexibleSpace with a button on edge



  • How to do this button in the right lower corner on the edge of SliverAppBar to move together in the zium:

    введите сюда описание изображения

    I tried to make it through SliverPersistentHeaderDelegate, but I couldn't make a Zoom image on the background, so I returned SliverAppBar.

    SliverAppBar(
    automaticallyImplyLeading: false,                   
    floating: true,
    pinned: true,
    snap: true,                       
    stretch: true,
    backgroundColor: Color(0xFFF8F9FD),
    expandedHeight: getHeight(450),                     
    flexibleSpace: FlexibleSpaceBar(   
    

    titlePadding: EdgeInsets.only(left: 20),

    collapseMode: CollapseMode.pin,
    stretchModes: [
      StretchMode.zoomBackground,
      
    ],
    background: Hero(
      tag: widget.card.id.toString(),
      child: Stack(
        children: [
          appBar(size),
          Positioned.fill(
            child: Align(
              alignment: Alignment.bottomRight,
              child: Padding(
                padding: const EdgeInsets.only(right: 20, top: 20),
                child: backButton(),
              ),
            ),
          )
        ],
      )
    ),
    

    ),

    ),



  • I thought it was hard for someone to use. Yeah, I really had to go through SliverPersistentHeaderDelegate.

    SliverPersistentHeader(
      delegate: LargeCustomHeader(
          child: appBar(size), //Картинка 
          btn: backButton(), //Кнопка
      )
    ),
    

    Further created the caste SliverPersistentHeader

    import 'package:flutter/material.dart';
    import 'package:flutter/rendering.dart';
    

    class LargeCustomHeader extends SliverPersistentHeaderDelegate {
    LargeCustomHeader({
    this.child,
    this.btn
    });
    final Widget child,btn;
    final double _navBarHeight = 56;
    final double titleHeight = 10;
    final double childrenHeight = 400;
    @override
    double get maxExtent => 400;

    @override
    double get minExtent => _navBarHeight;

    // @override
    // FloatingHeaderSnapConfiguration get snapConfiguration => FloatingHeaderSnapConfiguration() ;

    @override
    OverScrollHeaderStretchConfiguration get stretchConfiguration =>
    OverScrollHeaderStretchConfiguration(
    stretchTriggerOffset: maxExtent,
    onStretchTrigger: () {

        },
      );
    

    double get maxShrinkOffset => maxExtent - minExtent;

    @override
    bool shouldRebuild(SliverPersistentHeaderDelegate oldDelegate) {
    //TODO: implement specific rebuild checks
    return true;
    }

    @override
    Widget build(BuildContext context, double shrinkOffset, bool overlapsContent) {
    print(shrinkOffset);
    return Container(
    constraints: BoxConstraints.expand(),
    child: Stack(
    clipBehavior: Clip.none, fit: StackFit.loose,
    children: [
    child,
    Positioned(
    right: 20,
    bottom: -25,
    child: btn
    )
    ],
    ),
    );
    }
    }

    The most important thing is adding OverScrollHeaderStretchConfiguration, he's in charge of the zum of the image and in Stack, point clipBehavior: Clip.none, as the overflow parameter was removed



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2