text
stringlengths
1
372
),
);
}
}
<code_end>
by setting softWrap to true, text lines fill the column width before
wrapping at a word boundary.
<topic_end>
<topic_start>
update the app to display the text section
add a new TextSection widget as a child after the ButtonSection.
when adding the TextSection widget, set its description property to
the text of the location description.
<topic_end>
<topic_start>
add the image section
in this section, add the image file to complete your layout.
<topic_end>
<topic_start>
configure your app to use supplied images
to configure your app to reference images, modify its pubspec.yaml file.
create an images directory at the top of the project.
download the lake.jpg image and add it to the new images directory.
info
you can’t use wget to save this binary file.
you can download the image from unsplash
under the unsplash license. the small size comes in at 94.4 kB.
to include images, add an assets tag to the pubspec.yaml file
at the root directory of your app.
when you add assets, it serves as the set of pointers to the images
available to your code.
lightbulb tip
text in the pubspec.yaml respects whitespace and text case.
write the changes to the file as given in the previous example.
this change might require you to restart the running program to
display the image.
<topic_end>
<topic_start>
create the ImageSection widget
define the following ImageSection widget after the other declarations.
<code_start>
class ImageSection extends StatelessWidget {
const ImageSection({super.key, required this.image});
final string image;
@override
widget build(BuildContext context) {
return image.asset(
image,
width: 600,
height: 240,
fit: BoxFit.cover,
);
}
}
<code_end>
the BoxFit.cover value tells flutter to display the image with
two constraints. first, display the image as small as possible.
second, cover all the space that the layout allotted, called the render box.
<topic_end>
<topic_start>
update the app to display the image section
add an ImageSection widget as the first child in the children list.
set the image property to the path of the image you added in
configure your app to use supplied images.
<topic_end>
<topic_start>
congratulations
that’s it! when you hot reload the app, your app should look like this.
<topic_end>
<topic_start>
resources
you can access the resources used in this tutorial from these locations:
dart code: main.dart
image: ch-photo
pubspec: pubspec.yaml
<topic_end>
<topic_start>
next steps
to add interactivity to this layout, follow the
interactivity tutorial.
<topic_end>
<topic_start>
lists & grids
<topic_end>
<topic_start>
topics
<topic_end>
<topic_start>
use lists
displaying lists of data is a fundamental pattern for mobile apps.
flutter includes the ListView
widget to make working with lists a breeze.
<topic_end>
<topic_start>
create a ListView
using the standard ListView constructor is
perfect for lists that contain only a few items.
the built-in ListTile
widget is a way to give items a visual structure.
<code_start>