This question is being posted here as the related question here on stack overflow has only workarounds but no straight to the point approach.
One way to add gradient color to the AppBar is by using its flexibleSpace property. The flexibleSpace property of the AppBar accepts a widget as its value, so we can assign a container to it which itself implements a gradient background color.
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.
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,
),
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");
},
)
],
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With