Tags
Flutter
Asked 2 years ago
12 Oct 2021
Views 644
Connie

Connie posted

Flutter - how to style Text() widget ?


  Card(
              color: Colors.blue,

              child: Padding(
            padding: EdgeInsets.all(12),
              child:Container(

                  child:const Text( "Hello World",
                   )
              )
          )
          )


i applied color: Colors.blue to Card widget but it applies as a background color to Card, i want to change the text color to white
jagdish

jagdish
answered Oct 12 '21 00:00

Use style attribute of the Text widget, TextStyle class can be used with style attribute to change text color , font size , font weight etc..


  Card(
              color: Colors.blue,
              child: Padding(
                  padding: EdgeInsets.all(12),
                  child: Container(
                      child: const Text("Hello World",
                          style: TextStyle(color: Colors.white)))))

it give white color to text in the Card widget.

how to apply font style to Text widget in Flutter?
if want to change text normal to italic format then

Text("Hello World",
                          style: TextStyle(
                              fontStyle: FontStyle.italic,
                              color: Colors.white))

fontStyle: FontStyle.italic give italic text style

how to apply font weight to Text widget in Flutter?
now suppose want to applies font weight : bold

Text("Hello World",
                          style: TextStyle(
                              fontWeight: FontWeight.bold,
                              fontStyle: FontStyle.italic,
                              color: Colors.white))

fontWeight: FontWeight.bold make font bold .

how to apply background color to only Text widget in Flutter?

Text("Hello World",
                          style: TextStyle(
                              backgroundColor: Colors.red,
                              fontWeight: FontWeight.bold,
                              fontStyle: FontStyle.italic,
                              color: Colors.white))

backgroundColor: Colors.red, give red background color to Text Widget.
Post Answer