text stringlengths 1 372 |
|---|
mainAxisSize: MainAxisSize.min, |
crossAxisAlignment: CrossAxisAlignment.start, |
children: [ |
text( |
name, |
style: const TextStyle( |
color: colors.white, |
fontSize: 20, |
fontWeight: FontWeight.bold, |
), |
), |
text( |
country, |
style: const TextStyle( |
color: colors.white, |
fontSize: 14, |
), |
), |
], |
), |
); |
} |
} |
<code_end> |
next, add the list items to your ParallaxRecipe widget. |
<code_start> |
class ParallaxRecipe extends StatelessWidget { |
const ParallaxRecipe({super.key}); |
@override |
widget build(BuildContext context) { |
return SingleChildScrollView( |
child: column( |
children: [ |
for (final location in locations) |
LocationListItem( |
imageUrl: location.imageUrl, |
name: location.name, |
country: location.place, |
), |
], |
), |
); |
} |
} |
<code_end> |
you now have a typical, scrollable list of cards |
that displays seven unique locations in the world. |
in the next step, you add a parallax effect to the |
background image. |
<topic_end> |
<topic_start> |
implement the parallax effect |
a parallax scrolling effect is achieved by slightly |
pushing the background image in the opposite direction |
of the rest of the list. as the list items slide up |
the screen, each background image slides slightly downward. |
conversely, as the list items slide down the screen, |
each background image slides slightly upward. |
visually, this results in parallax. |
the parallax effect depends on the list item’s |
current position within its ancestor scrollable. |
as the list item’s scroll position changes, the position |
of the list item’s background image must also change. |
this is an interesting problem to solve. the position |
of a list item within the scrollable isn’t |
available until flutter’s layout phase is complete. |
this means that the position of the background image |
must be determined in the paint phase, which comes after |
the layout phase. fortunately, flutter provides a widget |
called flow, which is specifically designed to give you |
control over the transform of a child widget immediately |
before the widget is painted. in other words, |
you can intercept the painting phase and take control |
to reposition your child widgets however you want. |
info note |
to learn more, check out this short |
widget of the week video on the flow widget: |
info note |
in cases where you need control over what a child paints, |
rather than where a child is painted, |
consider using a CustomPaint widget. |
in cases where you need control over the layout, |
painting, and hit testing, consider defining a |
custom RenderBox. |
wrap your background image widget with a |
flow widget. |
<code_start> |
widget _buildParallaxBackground(BuildContext context) { |
return flow( |
children: [ |
image.network( |
imageUrl, |
fit: BoxFit.cover, |
), |
], |
); |
} |
<code_end> |
introduce a new FlowDelegate called ParallaxFlowDelegate. |
<code_start> |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.