text stringlengths 1 372 |
|---|
a list of cards (with rounded corners containing some text). |
each card also contains an image. |
as the cards slide up the screen, |
the images within each card slide down. |
the following animation shows the app’s behavior: |
<topic_end> |
<topic_start> |
create a list to hold the parallax items |
to display a list of parallax scrolling images, |
you must first display a list. |
create a new stateless widget called ParallaxRecipe. |
within ParallaxRecipe, build a widget tree with a |
SingleChildScrollView and a column, which forms |
a list. |
<code_start> |
class ParallaxRecipe extends StatelessWidget { |
const ParallaxRecipe({super.key}); |
@override |
widget build(BuildContext context) { |
return const SingleChildScrollView( |
child: column( |
children: [], |
), |
); |
} |
} |
<code_end> |
<topic_end> |
<topic_start> |
display items with text and a static image |
each list item displays a rounded-rectangle background |
image, representing one of seven locations in the world. |
stacked on top of that background image is the |
name of the location and its country, |
positioned in the lower left. between the |
background image and the text is a dark gradient, |
which improves the legibility |
of the text against the background. |
implement a stateless widget called LocationListItem |
that consists of the previously mentioned visuals. |
for now, use a static image widget for the background. |
later, you’ll replace that widget with a parallax version. |
<code_start> |
@immutable |
class LocationListItem extends StatelessWidget { |
const LocationListItem({ |
super.key, |
required this.imageUrl, |
required this.name, |
required this.country, |
}); |
final string imageUrl; |
final string name; |
final string country; |
@override |
widget build(BuildContext context) { |
return padding( |
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 16), |
child: AspectRatio( |
aspectRatio: 16 / 9, |
child: ClipRRect( |
borderRadius: BorderRadius.circular(16), |
child: stack( |
children: [ |
_buildParallaxBackground(context), |
_buildGradient(), |
_buildTitleAndSubtitle(), |
], |
), |
), |
), |
); |
} |
widget _buildParallaxBackground(BuildContext context) { |
return positioned.fill( |
child: image.network( |
imageUrl, |
fit: BoxFit.cover, |
), |
); |
} |
widget _buildGradient() { |
return positioned.fill( |
child: DecoratedBox( |
decoration: BoxDecoration( |
gradient: LinearGradient( |
colors: [colors.transparent, Colors.black.withOpacity(0.7)], |
begin: Alignment.topCenter, |
end: Alignment.bottomCenter, |
stops: const [0.6, 0.95], |
), |
), |
), |
); |
} |
widget _buildTitleAndSubtitle() { |
return positioned( |
left: 20, |
bottom: 20, |
child: column( |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.