Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change TextButton border colour - flutter

Tags:

flutter

dart

I have added a border to my TextButton.

TextButton(
  style: ButtonStyle(
      shape: MaterialStateProperty.all(RoundedRectangleBorder(
          borderRadius: BorderRadius.circular(0)))),
  onPressed: () {
    replacePoints();
  },
  child: Text(
    "${AppLocalizations.of(context)!.replacePoints} +",
    style: TextStyle(color: Colors.white),
  ))

How can I change its colour (only outline colour not background)?

like image 396
editix Avatar asked Sep 03 '26 16:09

editix


2 Answers

Try this:

TextButton(
    style: ButtonStyle(
        shape: MaterialStateProperty.all(RoundedRectangleBorder(
            side: BorderSide(
              color: Colors.red, // your color here
              width: 1,
            ),
            borderRadius: BorderRadius.circular(0)))),
    onPressed: () {
      replacePoints();
    },
    child: Text(
      "${AppLocalizations.of(context)!.replacePoints} +",
      style: TextStyle(color: Colors.white),
    ))
like image 126
manhtuan21 Avatar answered Sep 06 '26 05:09

manhtuan21


Try below code you will change Border color in two ways

  1. Using TextButton.styleFrom refer styleFrom

    TextButton(
          style: TextButton.styleFrom(
            side: BorderSide(
              color: Colors.green,
            ),
          ),
          onPressed: () {
            //write your onPressed function here
            print('Button Press');
          },
          child: Text(
            'Hello, World!',
            style: Theme.of(context).textTheme.headline4,
          ),
        ),
    

Result-> image

  1. Using ButtonStyle Class refer ButtonStyle

    TextButton(
      style: ButtonStyle(
        shape: MaterialStateProperty.all(
          RoundedRectangleBorder(
            side: BorderSide(
              color: Colors.blue,
            ),
            borderRadius: BorderRadius.circular(5),
          ),
        ),
      ),
      onPressed: () {
        //write your onPressed function here
        print('Button Press');
      },
      child: Text(
        'Hello, World!',
        style: Theme.of(context).textTheme.headline4,
      ),
    ),
    

Result-> image

like image 26
Ravindra S. Patil Avatar answered Sep 06 '26 06:09

Ravindra S. Patil



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!