text stringlengths 1 372 |
|---|
windows doesn’t support file name wildcarding. |
instead, list the .arb files that were generated by the |
intl_translation:extract_to_arb command. |
the DemoLocalizations class uses the generated |
initializeMessages() function |
(defined in intl_messages_all.dart) |
to load the localized messages and intl.message() |
to look them up. |
<topic_end> |
<topic_start> |
more information |
if you learn best by reading code, |
check out the following examples. |
if dart’s intl package is new to you, |
check out using the dart intl tools. |
<topic_end> |
<topic_start> |
state management |
<topic_end> |
<topic_start> |
topics |
<topic_end> |
<topic_start> |
state management |
info note |
if you have written a mobile app using flutter |
and wonder why your app’s state is lost |
on a restart, check out restore state on android |
or restore state on iOS. |
if you are already familiar with state management in reactive apps, |
you can skip this section, though you might want to review the |
list of different approaches. |
as you explore flutter, |
there comes a time when you need to share application |
state between screens, across your app. |
there are many approaches you can take, |
and many questions to think about. |
in the following pages, |
you will learn the basics of dealing with state in flutter apps. |
<topic_end> |
<topic_start> |
start thinking declaratively |
if you’re coming to flutter from an imperative framework |
(such as android SDK or iOS UIKit), you need to start |
thinking about app development from a new perspective. |
many assumptions that you might have don’t apply to flutter. for example, in |
flutter it’s okay to rebuild parts of your UI from scratch instead of modifying |
it. flutter is fast enough to do that, even on every frame if needed. |
flutter is declarative. this means that flutter builds its user interface to |
reflect the current state of your app: |
when the state of your app changes |
(for example, the user flips a switch in the settings screen), |
you change the state, and that triggers a redraw of the user interface. |
there is no imperative changing of the UI itself |
(like widget.setText)—you change the state, |
and the UI rebuilds from scratch. |
read more about the declarative approach to UI programming |
in the get started guide. |
the declarative style of UI programming has many benefits. |
remarkably, there is only one code path for any state of the UI. |
you describe what the UI should look |
like for any given state, once—and that is it. |
at first, |
this style of programming might not seem as intuitive as the |
imperative style. this is why this section is here. read on. |
<topic_end> |
<topic_start> |
differentiate between ephemeral state and app state |
this doc introduces app state, ephemeral state, |
and how you might manage each in a flutter app. |
in the broadest possible sense, the state of an app is everything that |
exists in memory when the app is running. this includes the app’s assets, |
all the variables that the flutter framework keeps about the UI, |
animation state, textures, fonts, and so on. while this broadest |
possible definition of state is valid, it’s not very useful for |
architecting an app. |
first, you don’t even manage some state (like textures). |
the framework handles those for you. so a more useful definition of |
state is “whatever data you need in order to rebuild your UI at any |
moment in time”. second, the state that you do manage yourself can |
be separated into two conceptual types: ephemeral state and app state. |
<topic_end> |
<topic_start> |
ephemeral state |
ephemeral state (sometimes called UI state or local state) |
is the state you can neatly contain in a single widget. |
this is, intentionally, a vague definition, so here are a few examples. |
other parts of the widget tree seldom need to access this kind of state. |
there is no need to serialize it, and it doesn’t change in complex ways. |
in other words, there is no need to use state management techniques |
(scopedmodel, redux, etc.) on this kind of state. |
all you need is a StatefulWidget. |
below, you see how the currently selected item in a bottom navigation bar is |
held in the _index field of the _MyHomepageState class. |
in this example, _index is ephemeral state. |
<code_start> |
class MyHomepage extends StatefulWidget { |
const MyHomepage({super.key}); |
@override |
State<MyHomepage> createState() => _MyHomepageState(); |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.