Want to add gradient color in AppBar in Flutter? Take a look at this example that I’ve pieced together from the Planets-Flutter tutorial along with the code below it.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | import "package:flutter/material.dart"; class Page extends StatelessWidget { @override Widget build(BuildContext context) { return Column(children : <Widget>[GradientAppBar("Custom Gradient App Bar"), Container()],); } } class GradientAppBar extends StatelessWidget { final String title; final double barHeight = 50.0; GradientAppBar(this.title); @override Widget build(BuildContext context) { final double statusbarHeight = MediaQuery .of(context) .padding .top; return new Container( padding: EdgeInsets.only(top: statusbarHeight), height: statusbarHeight + barHeight, child: Center( child: Text( title, style: TextStyle(fontSize: 20.0, color: Colors.white, fontWeight: FontWeight.bold), ), ), decoration: BoxDecoration( gradient: LinearGradient( colors: [Colors.red, Colors.blue], begin: const FractionalOffset(0.0, 0.0), end: const FractionalOffset(0.5, 0.0), stops: [0.0, 1.0], tileMode: TileMode.clamp ), ), ); } } |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.