Theming OutlinedButton for "disabled" state

912 views
Skip to first unread message

Zlati Pehlivanov

unread,
Dec 17, 2020, 9:02:38 AM12/17/20
to Flutter Development (flutter-dev)
Hi, people, Is there a way to specify the border color in "disabled" state of the new OutlinedButton in a theme specification? 
The text color is changing to grey without me doing anything specfic for the OutlinedButtonTheme  

Hans Muller

unread,
Dec 17, 2020, 8:13:50 PM12/17/20
to Zlati Pehlivanov, Flutter Development (flutter-dev)
The ButtonStyle.side property is a MaterialStateProperty<BorderSide> which can resolve to a non-default color for the disabled state. Here's an example that specifies the OutlinedButton's style directly. You could also specify an OutlinedButtonTheme.

import 'package:flutter/material.dart';

class Home extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: OutlinedButton(
          onPressed: null,
          style: ButtonStyle(
            side: MaterialStateProperty.resolveWith<BorderSide>((Set<MaterialState> states) {
              if (states.contains(MaterialState.disabled)) {
                return BorderSide(width: 2, color: Colors.green);
              }
              return null; // defer to the default for OutlinedButton
            }),
          ),
        ),
      ),
    );
  }
}

void main() {
  runApp(MaterialApp(home: Home()));
}

On Thu, Dec 17, 2020 at 6:02 AM Zlati Pehlivanov <zlati.pe...@gmail.com> wrote:
Hi, people, Is there a way to specify the border color in "disabled" state of the new OutlinedButton in a theme specification? 
The text color is changing to grey without me doing anything specfic for the OutlinedButtonTheme  

--
You received this message because you are subscribed to the Google Groups "Flutter Development (flutter-dev)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flutter-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/flutter-dev/84b78c0f-45e6-4b00-b125-78577698ec55n%40googlegroups.com.

Suzuki Tomohiro

unread,
Dec 18, 2020, 5:02:33 PM12/18/20
to Zlati Pehlivanov, Flutter Development (flutter-dev)
Something like this:

OutlinedButton(
  style: ButtonStyle(
    side: MaterialStateProperty.resolve((states)=> BorderSide(color: states.contains(MaterialState.disabled) ? Colors.red : Colors.yellow))
  )
)

(I didn't test this code.)


On Thu, Dec 17, 2020 at 9:02 AM Zlati Pehlivanov <zlati.pe...@gmail.com> wrote:
Hi, people, Is there a way to specify the border color in "disabled" state of the new OutlinedButton in a theme specification? 
The text color is changing to grey without me doing anything specfic for the OutlinedButtonTheme  

Zlati Pehlivanov

unread,
Dec 18, 2020, 9:32:34 PM12/18/20
to Suzuki Tomohiro, Flutter Development (flutter-dev)
Yes, it works.
--
Best Regards,
Zlati Pehlivanov
Reply all
Reply to author
Forward
0 new messages