text
stringlengths
1
372
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(
children: [text('t1')],
)
],
),
table(
children: const [
TableRow(
children: [text('t2')],
)
],
),
table(
children: const [
TableRow(
children: [text('t3')],
)
],
),
table(
children: const [
TableRow(
children: [text('t10')], // modified
)
],
),