text stringlengths 1 474 |
|---|
a 0-255 value encoding and have unpremultipled alpha.<topic_end> |
<topic_start>Samplers |
A sampler provides access to a dart:ui Image object. |
This image can be acquired either from a decoded image |
or from part of the application using |
Scene.toImageSync or Picture.toImageSync.By default, the image uses |
TileMode.clamp to determine how values outside |
of the range of [0, 1] behave. |
Customization of the tile mode is not |
supported and needs to be emulated in the shader.<topic_end> |
<topic_start> |
Performance considerations |
When targeting the Skia backend, |
loading the shader might be expensive since it |
must be compiled to the appropriate |
platform-specific shader at runtime. |
If you intend to use one or more shaders during an animation, |
consider precaching the fragment program objects before |
starting the animation.You can reuse a FragmentShader object across frames; |
this is more efficient than creating a new |
FragmentShader for each frame.For a more detailed guide on writing performant shaders, |
check out Writing efficient shaders on GitHub.<topic_end> |
<topic_start> |
Other resources |
For more information, here are a few resources. |
<topic_end> |
<topic_start>Add interactivity to your Flutter app |
<topic_end> |
<topic_start>What you'll learn |
How do you modify your app to make it react to user input? |
In this tutorial, you’ll add interactivity to an app that |
contains only non-interactive widgets. |
Specifically, you’ll modify an icon to make it tappable |
by creating a custom stateful widget that manages two |
stateless widgets.The building layouts tutorial showed you how to create |
the layout for the following screenshot.When the app first launches, the star is solid red, |
indicating that this lake has previously been favorited. |
The number next to the star indicates that 41 |
people have favorited this lake. After completing this tutorial, |
tapping the star removes its favorited status, |
replacing the solid star with an outline and |
decreasing the count. Tapping again favorites the lake, |
drawing a solid star and increasing the count.To accomplish this, you’ll create a single custom widget |
that includes both the star and the count, |
which are themselves widgets. Tapping the star changes state |
for both widgets, so the same widget should manage both.You can get right to touching the code in |
Step 2: Subclass StatefulWidget. |
If you want to try different ways of managing state, |
skip to Managing state.<topic_end> |
<topic_start> |
Stateful and stateless widgets |
A widget is either stateful or stateless. If a widget can |
change—when a user interacts with it, |
for example—it’s stateful.A stateless widget never changes. |
Icon, IconButton, and Text are |
examples of stateless widgets. Stateless widgets |
subclass StatelessWidget.A stateful widget is dynamic: for example, |
it can change its appearance in response to events |
triggered by user interactions or when it receives data. |
Checkbox, Radio, Slider, |
InkWell, Form, and TextField |
are examples of stateful widgets. Stateful widgets |
subclass StatefulWidget.A widget’s state is stored in a State object, |
separating the widget’s state from its appearance. |
The state consists of values that can change, like a |
slider’s current value or whether a checkbox is checked. |
When the widget’s state changes, |
the state object calls setState(), |
telling the framework to redraw the widget.<topic_end> |
<topic_start> |
Creating a stateful widget |
<topic_end> |
<topic_start>What's the point? |
In this section, you’ll create a custom stateful widget. |
You’ll replace two stateless widgets—the solid red |
star and the numeric count next to it—with a single |
custom stateful widget that manages a row with two |
children widgets: an IconButton and Text.Implementing a custom stateful widget requires creating two classes:This section shows you how to build a stateful widget, |
called FavoriteWidget, for the lakes app. |
After setting up, your first step is choosing how state is |
managed for FavoriteWidget.<topic_end> |
<topic_start> |
Step 0: Get ready |
If you’ve already built the app in the |
building layouts tutorial, |
skip to the next section.Once you have a connected and enabled device, |
or you’ve launched the iOS simulator |
(part of the Flutter install) or the |
Android emulator (part of the Android Studio |
install), you are good to go!<topic_end> |
<topic_start> |
Step 1: Decide which object manages the widget’s state |
A widget’s state can be managed in several ways, |
but in our example the widget itself, |
FavoriteWidget, will manage its own state. |
In this example, toggling the star is an isolated |
action that doesn’t affect the parent widget or the rest of |
the UI, so the widget can handle its state internally.Learn more about the separation of widget and state, |
and how state might be managed, in Managing state.<topic_end> |
<topic_start> |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.