Home > database >  How can I give my text a background color?
How can I give my text a background color?

Time:12-28

I want to give color to the text background like the picture below:

enter image description here

while mine is still like this:

enter image description here

And the code that I have written is like this:

Text(
                'Last Activity',
                style: TextStyle(
                  fontSize: 16,
                  color: ColorName.whitePrimary,
                ),
              ),

CodePudding user response:

body: Center(
        child: TextButton.icon(
          style: TextButton.styleFrom(
            textStyle: TextStyle(color: Colors.blue),
            backgroundColor: Colors.white,
            shape: RoundedRectangleBorder(
              borderRadius: BorderRadius.circular(6.0),
            ),
          ),
          onPressed: () => {},
          icon: Text('Last Activity'),
          label: Icon(Icons.chevron_right),
        ),
      ),

enter image description here

CodePudding user response:

Set the style parameter in your Text widget:

 Text(
      'Hello, World!',
      style: TextStyle(fontSize: 32, backgroundColor: Colors.green),
    );

Result

See also

  • image

    2. Using Row

       GestureDetector(
                onTap: () {},
                child: Container(
                  height: 30,//change on your need
                  width: 120,//change on your need
                  padding: const EdgeInsets.all(5),
                  alignment: Alignment.center,
                  color: const Color.fromRGBO(60, 75, 175, 1),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceAround,
                    children: const [
                        Text(
                        'Last Activity',
                        style: TextStyle(
                          color: Colors.white,
                        ),
                      ),
                        Icon(
                        Icons.chevron_right,
                        color: Colors.white,
                      ),
                    ],
                  ),
                ),
              ),
    

    Result Using Row-> image

    CodePudding user response:

    Try the following code:

    Text(
      'Last Activity',
      style: TextStyle(
        fontSize: 16,
        color: ColorName.whitePrimary,
      ),
    ),
    
  • Related