text
stringlengths
1
474
specified lines of Dart code to keep using hot reload.<topic_end>
<topic_start>
CupertinoTabView’s builder
Hot reload won’t apply changes made to
a builder of a CupertinoTabView.
For more information, see Issue 43574.<topic_end>
<topic_start>
Enumerated types
Hot reload doesn’t work when enumerated types are
changed to regular classes or regular classes are
changed to enumerated types.For example:Before the change:
<code_start>enum Color {
red,
green,
blue,
}<code_end>
After the change:
<code_start>class Color {
Color(this.i, this.j);
final int i;
final int j;
}<code_end>
<topic_end>
<topic_start>
Generic types
Hot reload won’t work when generic type declarations
are modified. For example, the following won’t work:Before the change:
<code_start>class A<T> {
T? i;
}<code_end>
After the change:
<code_start>class A<T, V> {
T? i;
V? v;
}<code_end>
<topic_end>
<topic_start>
Native code
If you’ve changed native code (such as Kotlin, Java, Swift,
or Objective-C), you must perform a full restart (stop and
restart the app) to see the changes take effect.<topic_end>
<topic_start>
Previous state is combined with new code
Flutter’s stateful hot reload preserves the state of your app.
This approach enables you to view the effect of the most
recent change only, without throwing away the current state.
For example, if your app requires a user to log in,
you can modify and hot reload a page several levels down in
the navigation hierarchy, without re-entering your login credentials.
State is kept, which is usually the desired behavior.If code changes affect the state of your app (or its dependencies),
the data your app has to work with might not be fully consistent
with the data it would have if it executed from scratch.
The result might be different behavior after a hot reload
versus a hot restart.<topic_end>
<topic_start>
Recent code change is included but app state is excluded
In Dart, static fields are lazily initialized.
This means that the first time you run a Flutter app and a
static field is read, it’s set to whatever value its
initializer was evaluated to.
Global variables and static fields are treated as state,
and are therefore not reinitialized during hot reload.If you change initializers of global variables and static fields,
a hot restart or restart the state where the initializers are hold
is necessary to see the changes.
For example, consider the following code:
<code_start>final sampleTable = [
Table(
children: const [
TableRow(
children: [Text('T1')],
)
],
),
Table(
children: const [
TableRow(
children: [Text('T2')],
)
],
),
Table(
children: const [
TableRow(
children: [Text('T3')],
)
],
),
Table(
children: const [
TableRow(
children: [Text('T4')],
)
],
),
];<code_end>
After running the app, you make the following change:
<code_start>final sampleTable = [
Table(
children: const [
TableRow(