Flutter OutlinedButton: set disabled color

Issue

On my Flutter app i have an OutlinedButton with rounded corners:

OutlinedButton(
  child: Text(
    "a label",
  ),
  onPressed: () {
     // do something
  },
  style: OutlinedButton.styleFrom(
    primary: Colors.white,
    backgroundColor: MyColor.colorAccent,
    shape: const RoundedRectangleBorder(
      borderRadius: BorderRadius.all(
        Radius.circular(10),
      ),
    ),
  ),
)

Now i need to style button for disabled status, but i don’t need how to know with this widget (on EevatedButton i’m using MaterialStateProperty.resolveWith as backgroundColor, but it’s not good for OutlinedButton)

Solution

this is not the best practice but you can do something like this

bool? _isdisabled ;
//null check , if u are on an older version of dart of you want to declare it just do this :
bool _isdisabled = false;
 
OutlinedButton(
  child: Text(
    "a label",
  ),
  onPressed: () {
     // do something
  },
  style:_isdisabled==false? OutlinedButton.styleFrom(
    primary: Colors.white,
    backgroundColor: MyColor.colorAccent,
    shape: const RoundedRectangleBorder(
      borderRadius: BorderRadius.all(
        Radius.circular(10),
      ),
    ),
  ): //another style ,
)

Answered By – Fahmi Sawalha

Answer Checked By – Timothy Miller (FlutterFixes Admin)

Leave a Reply

Your email address will not be published.