macosui / macos_ui

Flutter widgets and themes implementing the current macOS design language.
https://macosui.github.io/macos_ui/#/
MIT License
1.82k stars 178 forks source link

disabled background color force #261

Closed nbonamy closed 2 years ago

nbonamy commented 2 years ago

Needed to force disabled background color

GroovinChip commented 2 years ago

@nbonamy Thanks for the PR. Can you please provide some more information on your changes? What did you need this for? Can you provide a screenshot or gif that demonstrates your change?

nbonamy commented 2 years ago

Hello,

I am writing am image browser and viewer (https://github.com/nbonamy/foto) with functionalities similar to Finder. Hence I am using MacosTextField for the names of the files that I set to disabled. When user selects "Rename", I enable the field.

Still struggling with focus though...

SCR-20220530-kf7 SCR-20220530-kfg

Thanks

GroovinChip commented 2 years ago

Couldn't you achieve this effect simply by setting enabled: false and setting a custom decoration until the user clicks "rename"?

nbonamy commented 2 years ago

No because line 1311, effectiveDecoration is built with color being overridden with the calculated disabledColor if widget is disabled. I went for the simplest fix as I did not want to mess too much with the codebase. There maybe a more elegant solution 😀

GroovinChip commented 2 years ago

@whiplashoo what are your thoughts on this?

whiplashoo commented 2 years ago

OK, I think that enabling changing the disabled background color of a MacosTextField sounds reasonable.

However, @nbonamy in your specific use case, I think it would be best to either:

bool isRenaming = false;
TextEditingController renameController = TextEditingController()
  ..text = "Test name";

SizedBox(
  width: 300.0,
  child: isRenaming
      ? MacosTextField(
          controller: renameController,
        )
      : GestureDetector(
          onDoubleTap: () => setState(() => isRenaming = true),
          child: Text(renameController.text)),
  ),

It would be more natural I think; having a disabled text field for the label seems a bit hacky. It's probably what MacOS Finder does under the hood, and you can also have more control over the labels when inactive.

SizedBox(
  width: 300.0,
  child: GestureDetector(
    onDoubleTap: () => setState(() => isRenaming = true),
    child: MacosTextField(
      readOnly: isRenaming ? false : true,
      controller: renameController,
      decoration: BoxDecoration(
        border: Border.all(color: Colors.transparent),
      ),
    ),
  ),
),

Please have a look at these suggestion in case they help with your project!

nbonamy commented 2 years ago

Thanks! Will look into doing differently.

GroovinChip commented 2 years ago

Closing until further notice

nbonamy commented 2 years ago

Thought that your comment "OK, I think that enabling changing the disabled background color of a MacosTextField sounds reasonable." meant you were going to accept the PR 😀

GroovinChip commented 2 years ago

Later discussion indicates that there are other methods of achieving this, which you are going to look into. If nothing else pans out, update me here and I'll re-open the PR.

nbonamy commented 2 years ago

Hi. Tried both solutions.

1) Going back and forth from Text to MacosTextField seems to pose some problem. Specifically, getting "setState() called after dispose(): _MacosTextFieldState" from _handleFocusChanged. Maybe something is wrong with my implementation but I kept it as simple as possible

2) readonly shows a caret cursor which is not desirable

Regards Nicolas