I want to give color to the text background like the picture below:
while mine is still like this:
And the code that I have written is like this:
Text( 'Last Activity', style: TextStyle( fontSize: 16, color: ColorName.whitePrimary, ), ),
5
Set the style parameter in your Text widget:
style
Text
Text( 'Hello, World!', style: TextStyle(fontSize: 32, backgroundColor: Colors.green), );
TextStyle
Try the following code:
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), ), ),
Text( 'Last Activity', style: TextStyle( fontSize: 16, color: ColorName.whitePrimary, backgroundColor: Colors.indigo[400], ), ),
Refer below code hope its help to you, I have try 2 ways TextButton.icon and Row
TextButton.icon
Row
TextButton.icon( style: TextButton.styleFrom( foregroundColor: Colors.white, backgroundColor: const Color.fromRGBO(60, 75, 175, 1), shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(6.0), ), ), onPressed: () => {}, icon: const Text('Last Activity'), label: const Icon(Icons.chevron_right), ),
Result Using TextButton.icon->
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->
Click here to cancel reply.
5
Answers
Set the
style
parameter in yourText
widget:See also
TextStyle
(flutter.dev)Try the following code:
Try the following code:
Refer below code hope its help to you, I have try 2 ways
TextButton.icon
andRow
1. Using TextButton Widget
Result Using TextButton.icon->
2. Using Row
Result Using Row->