Skip to main content

Set Change Text Color in Flutter

The text widget in flutter has a property color which is a sub property of TextStyle. Color property change text color in flutter. We are using default color constants which comes inbuilt with flutter to change the color of text. There are almost 52 default color constant available in flutter. I am listing all of them below.

List of all color constants available in flutter:

  1. Colors.amber
  2. Colors.amberAccent
  3. Colors.black
  4. Colors.black12
  5. Colors.black26
  6. Colors.black38
  7. Colors.black48
  8. Colors.black54
  9. Colors.black87
  10. Colors.blue
  11. Colors.blueAccent
  12. Colors.blueGrey
  13. Colors.brown
  14. Colors.cyan
  15. Colors.cyanAccent
  16. Colors.deepOrange
  17. Colors.deepOrangeAccent
  18. Colors.deepPurple
  19. Colors.deepPurpleAccent
  20. Colors.green
  21. Colors.greenAccent
  22. Colors.grey
  23. Colors.indigo
  24. Colors.indigoAccent
  25. Colors.lightBlue
  26. Colors.lightBlueAccent
  27. Colors.lightGreen
  28. Colors.lightGreenAccent
  29. Colors.lime
  30. Colors.limeAccent
  31. Colors.orange
  32. Colors.orangeAccent
  33. Colors.pink
  34. Colors.pinkAccent
  35. Colors.purple
  36. Colors.purpleAccent
  37. Colors.red
  38. Colors.redAccent
  39. Colors.teal
  40. Colors.tealAccent
  41. Colors.transparent
  42. Colors.white
  43. Colors.white10
  44. Colors.white12
  45. Colors.white24
  46. Colors.white30
  47. Colors.white38
  48. Colors.white54
  49. Colors.white60
  50. Colors.white70
  51. Colors.yellow
  52. Colors.yellowAccent

Set Change Text Color in Flutter:

1. I am creating 3 Text widgets each with different color. Here I am using Colors object and using default color constants inside it.
  Text(
          'Sample Text One',
          style: TextStyle(fontSize: 24, color: Colors.yellowAccent),
        ),
        Text(
          'Sample Text Two',
          style: TextStyle(fontSize: 24, color: Colors.blue),
        ),
        Text(
          'Sample Text Three',
          style: TextStyle(fontSize: 24, color: Colors.orange),
        )
2. Complete source code for main.dart file:
import 'package:flutter/material.dart';

void main() => runApp(App());

class App extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      home: Scaffold(
          body: SafeArea(
              child: Center(
                  child: Column(children: [
        Text(
          'Sample Text One',
          style: TextStyle(fontSize: 24, color: Colors.yellowAccent),
        ),
        Text(
          'Sample Text Two',
          style: TextStyle(fontSize: 24, color: Colors.blue),
        ),
        Text(
          'Sample Text Three',
          style: TextStyle(fontSize: 24, color: Colors.orange),
        ),
      ])))),
    );
  }
}
Screenshot of App:
Set Change Text Color in Flutter

Comments