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

C2Chip text color is not adjustable #36

Closed
slavap opened this issue Sep 10, 2022 · 3 comments
Closed

C2Chip text color is not adjustable #36

slavap opened this issue Sep 10, 2022 · 3 comments

Comments

@slavap
Copy link

slavap commented Sep 10, 2022

Currently there is the following code in C2Chip.build():

    final TextStyle defaultLabelStyle =
        TextStyle().merge(chipTheme.labelStyle).merge(style?.labelStyle);

    final TextStyle primaryLabelStyle =
        defaultLabelStyle.copyWith(color: foregroundColor);

    final TextStyle selectedLabelStyle = defaultLabelStyle.copyWith(
      color:
          isElevated ? Colors.white : secondaryColor.withAlpha(foregroundAlpha),
    );

So there is no way to specify font color for chips, because labelStyle color is just ignored. That leads to strange color combinations, for example blue background with opacity 0.12 and blue text with opacity 0.87 on it, which is barely readable.
Currently the following code is not working, though it definitely should:

choiceActiveStyle: C2ChoiceStyle(color: Colors.blue, opacity: 1, labelStyle: TextStyle().copyWith(color: Colors.yellow));
@dewygame1
Copy link

dewygame1 commented Sep 28, 2022

try this

class CustomChip extends StatelessWidget {
  final String label;
  final Color? color;
  final double? width;
  final double? height;
  final EdgeInsetsGeometry? margin;
  final bool selected;
  final Function(bool selected) onSelect;

  const CustomChip({
    Key? key,
    required this.label,
    this.color,
    this.width,
    this.height,
    this.margin,
    this.selected = false,
    required this.onSelect,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return RawChip(
      clipBehavior: Clip.none,
      label: Text(label),
      labelStyle: selected ? textStyle(color: AppColors.primary, fontWeight: FontWeight.bold) : textStyle(color: Colors.black),
      backgroundColor: selected ? Color(0xFFFFE2EA) : Color(0xFFEEEEEE),
      padding: EdgeInsets.fromLTRB(17, 2, 17, 2),
      onPressed: () => onSelect(!selected),
    );
  }
}

And use

choiceBuilder: (item) {
                              return Container(
                                margin: EdgeInsets.symmetric(horizontal: 5, vertical: 3),
                                child: CustomChip(
                                  label: item.label,
                                  height: 100,
                                  selected: item.selected,
                                  onSelect: item.select!,
                                ),
                              );
                            }

@slavap
Copy link
Author

slavap commented Sep 28, 2022

@dewygame1 Thanks, I know how to workaround this issue. But expecting to see “normal” fix without need of any workarounds.

@davigmacode
Copy link
Owner

Hi everyone,

I'm sorry to announce that I'm no longer maintaining the chips_choice package. It's been a great project, but it's become too difficult to maintain.

In its place, I've released a new package called choice. The combination to smart_select and chips_choice with cleaner, more flexible, and composable API for creating inline or prompted choice widgets with single or multiple selection.

I hope you'll check out choice. I think you'll find it to be a great replacement for chips_choice.

Thanks for your understanding.

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

3 participants