Search code examples
flutterdartcolorstransition

Flutter smooth color transition container


How can I make say a container with a shaded color like the picture attached?

I do not just use an image, because it would be a lot harder to make thodr small changes to it, and the color needs to be the whole screen width at times, and maybe I'm going to animate it.

https://i.sstatic.net/2QzXC.jpg


Solution

  • You can use the gradient property of the BoxDecoration to get what you want.

    I added a demo:

    class StackOver extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          body: Container(
            decoration: BoxDecoration(
              gradient: LinearGradient(
                colors: [
                  // use your preferred colors 
                  Colors.red[900],
                  Colors.blue[900],
                ],
                // start at the top
                begin: Alignment.topCenter,
               // end at the bottom
                end: Alignment.bottomCenter,
              ),
            ),
          ),
        );
      }
    }
    
    

    RESULT:

    result