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

Change chip color according to its value #164

Open
mathlizee opened this issue Sep 26, 2024 · 1 comment
Open

Change chip color according to its value #164

mathlizee opened this issue Sep 26, 2024 · 1 comment

Comments

@mathlizee
Copy link

Hello!

In chipConfig, I can change the background color of all chips easily.

However, I would like to have a different background color for each chip according to its value. My usecase is that each chip represents a document state (In Progress, Closed, Billed, etc.) and that each state is represented by a color.

Would it be possible to allow configuring a chip according to its binded value?

Thanks!
Mathieu

@Yogesh070
Copy link

You can do that using selectedItemBuilder property to conditionally style item. However you have to manage remove selected chip yourself using controller. Example : Assuming you are using v2 of the API. @mathlizee

selectedItemBuilder: (context,item) {
                              return Chip(
                                label: Text(
                                  item.label,
                                  style: const TextStyle(color: Colors.white),
                                ),
                                backgroundColor: switch (item.label) {
                                  'Closed' => Colors.red,
                                  'Billed' => Colors.blue,
                                  _ => Colors.green,
                                },
                              );
                            },

Using v3 api

selectedItemBuilder: (item) {
                              return Chip(
                                label: Text(
                                  item.label,
                                  style: const TextStyle(color: Colors.white),
                                ),
                                backgroundColor: switch (item.label) {
                                  'Closed' => Colors.red,
                                  'Billed' => Colors.blue,
                                  _ => Colors.green,
                                },
                              );
                            },

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