flutterflutter-image

Blend image over image with crossfade at bottom


I have this background image gradient

enter image description here

And I got an artist image that I want to have above it as an overlay, blending into it and at the bottom it should cross fade into the other image.

Left is how I want it to look, right is how it looks right now:

enter image description here enter image description here

So what is missing is the crossfade at the bottom into the background gradient image.

This is my code for now:

Container(
    decoration: BoxDecoration(
      image: DecorationImage(
        image: Assets.package.gradient.provider(),
        fit: BoxFit.cover,
      ),
    ),
    constraints: BoxConstraints(
      minHeight: MediaQuery.of(context).size.height -
          MainAppBar.mainAppBarSize,
    ),
    width: width,
    child: Stack(
      children: [
        Positioned(
          left: -increasePixels,
          right: -increasePixels,
          top: -increasePixels,
          child: Container(
            decoration: BoxDecoration(
              image: DecorationImage(
                fit: BoxFit.cover,
                colorFilter: ColorFilter.mode(
                  Colors.black.withOpacity(0.3),
                  BlendMode.dstIn,
                ),
                image: Assets.package.artist.provider(),
              ),
            ),
            width: width + increasePixels * 2,
            height: (width + increasePixels * 2) *
                widget.imageAspectRatio,
          ),
        ),
    ],)
)

How can I do the crossfade?


Solution

  • Thanks to the comment of @pskink I figured it out.

    I wrapped my artist container image with this:

    ShaderMask(
        blendMode: BlendMode.dstIn,
        shaderCallback: (Rect bounds) {
          return const LinearGradient(
            begin: Alignment.topCenter,
            end: Alignment.bottomCenter,
            stops: [
              0.7,
              1,
            ],
            tileMode: TileMode.mirror,
            colors: [Colors.black, Colors.transparent],
          ).createShader(bounds);
        },
        child: