Gradients Background

Time to make the app a little prettier by adding a gradient background.

Gradients are just as easy in Flutter as the are in CSS. And that's good since they're so hot right now.

To use gradients, you first need a Container widget, and within that you need to access its decoration property.

Start by building the decoration of the Container widget in your _MyHomePageState build method in main.dart.

  1. // main.dart
  2. @override
  3. Widget build(BuildContext context) {
  4. return Scaffold(
  5. appBar: AppBar(
  6. title: Text(widget.title),
  7. backgroundColor: Colors.black87,
  8. ),
  9. body: Container(
  10. // Add box decoration
  11. decoration: BoxDecoration(
  12. // Box decoration takes a gradient
  13. gradient: LinearGradient(
  14. // Where the linear gradient begins and ends
  15. begin: Alignment.topRight,
  16. end: Alignment.bottomLeft,
  17. // Add one stop for each color. Stops should increase from 0 to 1
  18. stops: [0.1, 0.5, 0.7, 0.9],
  19. colors: [
  20. // Colors are easy thanks to Flutter's Colors class.
  21. Colors.indigo[800],
  22. Colors.indigo[700],
  23. Colors.indigo[600],
  24. Colors.indigo[400],
  25. ],
  26. ),
  27. ),
  28. child: Center(
  29. child: DogList(initialDoggos),
  30. ),
  31. ),
  32. );
  33. }

Now, gradients:

gradient screen shot