9

This question is being posted here as the related question here on stack overflow has only workarounds but no straight to the point approach.

2 Answers 2

15

this can be achieved with the fallowing code

AppBar(
  flexibleSpace: Container(
   decoration: BoxDecoration(
    gradient: LinearGradient(
      colors: [Colors.cyan, Colors.yellow], stops: [0.5, 1.0],
      ),
    ),
  ),
),

See the Pen bGVBVpz by yadunandan (@iamyadunandan) on CodePen.

Sign up to request clarification or add additional context in comments.

2 Comments

Excellent, this is beautiful, why does pub.dev/packages/gradient_app_bar exist? xD
This feature was introduced after the package, I guess
7

For a simple appbar with a gradient background and centered title,

AppBar(
      automaticallyImplyLeading: false, // hides default back button
      flexibleSpace: Container(
          decoration: BoxDecoration(
        gradient: LinearGradient(
            begin: Alignment.topLeft,
            end: Alignment.topRight,
            colors: [
              Color(0xffB1097C),
              Color(0xff0947B1),
            ]),
      )),
      title: Text("WishList", style: TextStyle(fontSize: 20.0, color: Colors.white)),
      centerTitle: true,
    ),

enter image description here

For a more complex appbar with a gradient background and action icons

AppBar(
  automaticallyImplyLeading: false, // hides default back button
  flexibleSpace: Container(
      decoration: BoxDecoration(
    gradient: LinearGradient(
        begin: Alignment.topLeft,
        end: Alignment.topRight,
        colors: [
          Color(0xffB1097C),
          Color(0xff0947B1),
        ]),
  )),
  title: Text("Welcome guest", style: TextStyle(fontSize: 20.0, color: Colors.white)),
  actions: [
    IconButton(
        icon: SvgPicture.asset("enter svg path",height: 20.0, width: 20.0),
        onPressed: () {
          print("Icon 1 pressed");
        }),
    IconButton(
      icon: SvgPicture.asset("enter svg path", height: 20.0, width: 20.0),
      onPressed: () {
        print("Icon 2 pressed");
      },
    )
  ],
)

enter image description here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.