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:
- Colors.amber
- Colors.amberAccent
- Colors.black
- Colors.black12
- Colors.black26
- Colors.black38
- Colors.black48
- Colors.black54
- Colors.black87
- Colors.blue
- Colors.blueAccent
- Colors.blueGrey
- Colors.brown
- Colors.cyan
- Colors.cyanAccent
- Colors.deepOrange
- Colors.deepOrangeAccent
- Colors.deepPurple
- Colors.deepPurpleAccent
- Colors.green
- Colors.greenAccent
- Colors.grey
- Colors.indigo
- Colors.indigoAccent
- Colors.lightBlue
- Colors.lightBlueAccent
- Colors.lightGreen
- Colors.lightGreenAccent
- Colors.lime
- Colors.limeAccent
- Colors.orange
- Colors.orangeAccent
- Colors.pink
- Colors.pinkAccent
- Colors.purple
- Colors.purpleAccent
- Colors.red
- Colors.redAccent
- Colors.teal
- Colors.tealAccent
- Colors.transparent
- Colors.white
- Colors.white10
- Colors.white12
- Colors.white24
- Colors.white30
- Colors.white38
- Colors.white54
- Colors.white60
- Colors.white70
- Colors.yellow
- 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:
Comments
Post a Comment