content: import 'package:flutter/cupertino.dart';
  import 'package:flutter/material.dart';
  import 'package:flutter/widgets.dart';
  import 'package:flutter_animations/flutter_design_challenges/spotify_album_view/const.dart';
  import 'package:flutter_animations/flutter_design_challenges/spotify_album_view/sliver_custom_appbar/custom_flexible_space.dart';
  import 'package:flutter_animations/flutter_design_challenges/spotify_album_view/sliver_custom_appbar/fixed_appbar.dart';
  import 'package:flutter_animations/flutter_design_challenges/spotify_album_view/sliver_custom_appbar/sliver_appbar_delegate.dart';
  
  class SliverCustomeAppBar extends StatelessWidget {
    const SliverCustomeAppBar({
      Key? key,
      required this.maxAppBarHeight,
      required this.minAppBarHeight,
    }) : super(key: key);
  
    final double maxAppBarHeight;
    final double minAppBarHeight;
  
    @override
    Widget build(BuildContext context) {
      final extraTopPadding = MediaQuery.of(context).size.height * 0.05;
      //app bar content padding
      final padding = EdgeInsets.only(
          top: MediaQuery.of(context).padding.top + extraTopPadding,
          right: 10,
          left: 10);
  
      return SliverPersistentHeader(
          pinned: true,
          delegate: SliverAppBarDelegate(
              maxHeight: maxAppBarHeight,
              minHeight: minAppBarHeight,
              builder: (context, shrinkOffset) {
                final appBarVisible =
                    shrinkOffset >= (maxAppBarHeight - minAppBarHeight);
                print(appBarVisible);
                final double shrinkToMaxAppBarHeightRatio =
                    shrinkOffset / maxAppBarHeight;
                const double animatAlbumImageFromPoint = 0.4;
                final animateAlbumImage =
                    shrinkToMaxAppBarHeightRatio >= animatAlbumImageFromPoint;
                final animateOpacityToZero = shrinkToMaxAppBarHeightRatio > 0.6;
                final albumPositionFromTop = animateAlbumImage
                    ? (animatAlbumImageFromPoint - shrinkToMaxAppBarHeightRatio) *
                        maxAppBarHeight
                    : null;
                final albumImageSize =
                    MediaQuery.of(context).size.height * 0.3 - shrinkOffset / 2;
                final showFixedAppBar = shrinkToMaxAppBarHeightRatio > 0.7;
                final double titleOpacity = showFixedAppBar
                    ? 1 - (maxAppBarHeight - shrinkOffset) / minAppBarHeight
                    : 0;
  
                return Stack(
                  alignment: Alignment.topCenter,
                  children: [
                    Positioned(
                      top: albumPositionFromTop,
                      child: AlbumImage(
                        padding: padding,
                        animateOpacityToZero: animateOpacityToZero,
                        animateAlbumImage: animateAlbumImage,
                        shrinkToMaxAppBarHeightRatio:
                            shrinkToMaxAppBarHeightRatio,
                        albumImageSize: albumImageSize,
                      ),
                    ),
                    AnimatedContainer(
                      duration: const Duration(milliseconds: 150),
                      decoration: BoxDecoration(
                        gradient: showFixedAppBar
                            ? const LinearGradient(
                                begin: Alignment.topCenter,
                                end: Alignment.bottomCenter,
                                colors: [
                                    kAppBarPrimary,
                                    kAppBarSecondary,
                                  ],
                                stops: [
                                    0,
                                    0.5
                                  ])
                            : null,
                      ),
                      child: Padding(
                        padding: padding,
                        child: SizedBox(
                          width: MediaQuery.of(context).size.width,
                          height: double.maxFinite,
                          child: FixedAppBar(titleOpacity: titleOpacity),
                        ),
                      ),
                    ),
                  ],
                );
              }));
    }
  }
  