flutter_chips_choice icon indicating copy to clipboard operation
flutter_chips_choice copied to clipboard

C2Chip text color is not adjustable

Open slavap opened this issue 3 years ago • 2 comments

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));

slavap avatar Sep 10 '22 03:09 slavap

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!,
                                ),
                              );
                            }

dewygame1 avatar Sep 28 '22 09:09 dewygame1

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

slavap avatar Sep 28 '22 09:09 slavap

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.

davigmacode avatar Aug 26 '23 12:08 davigmacode