Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot change border(bottom) color #13

Open
hafquangbaox opened this issue Jan 19, 2021 · 1 comment
Open

Cannot change border(bottom) color #13

hafquangbaox opened this issue Jan 19, 2021 · 1 comment

Comments

@hafquangbaox
Copy link

hafquangbaox commented Jan 19, 2021

        decoration: widget.state != null
            ? widget.decoration ??
                BoxDecoration(
                  border: Border(
                    bottom: BorderSide(
                      color: widget.state != null && widget.state.hasError
                          ? Colors.red.shade800.withOpacity(0.6)
                          : _selectedItems.isNotEmpty
                              ? (widget.selectedColor != null &&
                                      widget.selectedColor !=
                                          Colors.transparent)
                                  ? widget.selectedColor
                                  : Theme.of(context).primaryColor
                              : Colors.black45,
                      width: _selectedItems.isNotEmpty
                          ? (widget.state != null && widget.state.hasError)
                              ? 1.4
                              : 1.8
                          : 1.2,
                    ),
                  ),
                )
            : widget.decoration,

There is a lot of code like this. It draws a black frame border below the input. It broke my color design, it took me a day to find a way to override the colors but the result was impossible except for me to edit the entire file in the package.
If you have allowed drawing this frame border should allow the user to overwrite other colors.

This package is awesome, until I couldn't fix this black :)

@CHB61
Copy link
Owner

CHB61 commented Feb 15, 2021

@lozthiensu Hello,

Now that I'm looking at this code, I believe the initial null check for state (FormFieldState) is not necessary. In previous versions, there was

  • MultiSelectField - not a FormField and by default not drawn with a bottom border
  • MultiSelectFormField - FormField and drawn with bottom border
    and now there's only the FormField version, so state shouldn't be null.

However it has always been possible to override this default bottom border by providing a decoration parameter to the MultiSelectDialogField or MultiSelectBottomSheetField.

I am able to override the default black border with this example

MultiSelectDialogField(
  onConfirm: (val) {
    _selectedAnimals = val;
  },
  items: _items,
  decoration: BoxDecoration(
    border: Border(
      bottom: BorderSide(
        color: Colors.blue,
      ),
    ),
  ),
),

Doing this removes the default behavior of switching to a red underline when the FormFieldState has an error. If you wanted to retain that, you'd have to do something like

border: Border(
  bottom: BorderSide(
    color: _multiSelectKey.currentState != null &&
            _multiSelectKey.currentState.hasError
        ? Colors.red
        : Colors.blue,
  ),
),

and then setState after you call validate on the _multiSelectKey.

Can you provide an example where you are unable to achieve what you want?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants