text stringlengths 1 474 |
|---|
class ButtonWithText extends StatelessWidget { |
const ButtonWithText({ |
super.key, |
required this.color, |
required this.icon, |
required this.label, |
}); |
final Color color; |
final IconData icon; |
final String label; |
@override |
Widget build(BuildContext context) { |
return Column( |
// ··· |
); |
} |
}<code_end> |
<topic_end> |
<topic_start> |
Update the app to display the button section |
Add the button section to the children list.<topic_end> |
<topic_start> |
Add the Text section |
In this section, add the text description to this app.<topic_end> |
<topic_start> |
Add the TextSection widget |
Add the following code as a separate widget after the ButtonSection widget. |
<code_start>class TextSection extends StatelessWidget { |
const TextSection({ |
super.key, |
required this.description, |
}); |
final String description; |
@override |
Widget build(BuildContext context) { |
return Padding( |
padding: const EdgeInsets.all(32), |
child: Text( |
description, |
softWrap: true, |
), |
); |
} |
}<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 TipText 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 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.