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
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.
Since you are not providing any code, I may assume you are declaring the theme with
const
value.See deme below:
to update
cCl
i just need hot reload. but forfCl
hot reload doest works. I need to hot restart to update the UIIn 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.see the differences?
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.cCl
is a constant. When you change its value in the code and hot reload, the change takes effect becausecCl
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, andcCl
being a constant. Changes to the initial value offCl
require a full restart to take effect, while changes tocCl
can be seen with a hot reload.To see the new value of
fCl
after a hot reload, you would need to reassignfCl
to a new value at runtime. But since you’re assigning aconst
value tofCl
, you can’t reassignfCl
to a new value at runtime, so you need to perform a full restart of the application to see the new value offCl
.