skip to Main Content

I recently changed the color palette for my flutter app. However, when I run it I initially see the old color palette.

The only way to see the new changes is to tap restart even when it is a fresh instance.
This is iOS. I’ve have tried Erase All Content and Settings (which ought not be necessary) but to no avail.

flutter doctor is clean – no issues.

No errors shown in the console.

Any guidance would be appreciated.

2

Answers


  1. Chosen as BEST ANSWER

    In my case, I had stopped using the ThemeData colorScheme as it was not providing the experience that I wanted. However, I did have several remaining calls to IconThemeData for a couple of AppBar() instances.

    Apparently, underneath, those remaining calls were holding on to the original code. Commenting this calls out and then restarting solved the solution. This seems to be a bug with the framework.


  2. Since you are not providing any code, I may assume you are declaring the theme with const value.

    See deme below:

    • ⚡: hot reload
    • ↻ : Hot restart

    to update cCl i just need hot reload. but for fCl hot reload doest works. I need to hot restart to update the UI

    enter image description here


    In Dart, when you declare a variable as const, it means that the variable itself is a compile-time constant. Any changes to the value of this variable will require a full restart of the application to take effect, as the value is determined at compile-time.

    Color fCl = const Color.fromARGB(255, 228,179, 152)
    const Color cCl = Color.fromARGB(255,174, 98, 202)
    

    see the differences?

    1. fCl is a variable that is initialized with a constant value. It’s not a constant itself, but its initial value is. When you change its value in the code and hot reload, the change doesn’t take effect because the initial value is determined at compile-time.

    2. cCl is a constant. When you change its value in the code and hot reload, the change takes effect because cCl is a compile-time constant and its value is directly used where it’s referenced.

    So, the difference in behavior is due to fCl being a variable with a constant value, and cCl being a constant. Changes to the initial value of fCl require a full restart to take effect, while changes to cCl can be seen with a hot reload.

    To see the new value of fCl after a hot reload, you would need to reassign fCl to a new value at runtime. But since you’re assigning a const value to fCl, you can’t reassign fCl to a new value at runtime, so you need to perform a full restart of the application to see the new value of fCl.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search