Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

602
Views
Change color based on firebase value within flutter decoration

I have a decoration that I wish to change of based on a value return from firebase.
Currently, I have my decoration like below

decoration: const BoxDecoration(
                  border: Border(
                      left: BorderSide(
                          color: getColor(task.status), width: 5))),

This is my switch statement which I was hoping would return the right colour

Color getColor(Color status) {
  switch (status.toString()) {
    case 'Draft':
      return const Color.fromRGBO(255, 203, 51, 1);
    case 'Posted':
      return const Color.fromRGBO(10, 217, 163, 1);
    case 'Offered':
      return const Color.fromRGBO(20, 152, 204, 1);
    case 'Assigned':
      return const Color.fromRGBO(14, 116, 178, 1);
    case 'Overdue':
      return const Color.fromRGBO(222, 80, 66, 1);
    default:
      return const Color.fromRGBO(144, 163, 167, 1);
  }
}
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

getColor(Color status) 

This above method says that you are supposed to pass Color type and then you're trying to convert into string and matching it with "Draft", "Posted" etc. There are no colors by that name my friend.

First if you're getting error like "Invalid constant value". Please remove const from your code. It's not needed.

Your getColor() method looks just fine and should work like your're expecting. You just need to pass correct value (may be not Color type but simple string should work).

I tried your code on flutter dev and it works.

This one is where I'm calling your getColor method, I just tried simple string as an argument

enter image description here

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!