text stringlengths 1 474 |
|---|
width: 440, |
child: leftColumn, |
), |
mainImage, |
], |
), |
), |
), |
),<code_end> |
lightbulb Tip |
The Pavlova example runs best horizontally on a wide device, |
such as a tablet. If you are running this example in the iOS simulator, |
you can select a different device using the Hardware > Device menu. |
For this example, we recommend the iPad Pro. |
You can change its orientation to landscape mode using |
Hardware > Rotate. You can also change the size of the |
simulator window (without changing the number of logical pixels) |
using Window > Scale.App source: pavlova<topic_end> |
<topic_start> |
Common layout widgets |
Flutter has a rich library of layout widgets. |
Here are a few of those most commonly used. |
The intent is to get you up and running as quickly as possible, |
rather than overwhelm you with a complete list. |
For information on other available widgets, |
refer to the Widget catalog, |
or use the Search box in the API reference docs. |
Also, the widget pages in the API docs often make suggestions |
about similar widgets that might better suit your needs.The following widgets fall into two categories: standard widgets |
from the widgets library, and specialized widgets from the |
Material library. Any app can use the widgets library but |
only Material apps can use the Material Components library.<topic_end> |
<topic_start> |
Standard widgets |
<topic_end> |
<topic_start> |
Material widgets |
<topic_end> |
<topic_start> |
Container |
Many layouts make liberal use of Containers to separate |
widgets using padding, or to add borders or margins. |
You can change the device’s background by placing the |
entire layout into a Container and changing its background |
color or image.<topic_end> |
<topic_start>Summary (Container) |
<topic_end> |
<topic_start>Examples (Container) |
This layout consists of a column with two rows, each containing |
2 images. A Container is used to change the background color |
of the column to a lighter grey.A Container is also used to add a rounded border and margins |
to each image: |
<code_start>Widget _buildDecoratedImage(int imageIndex) => Expanded( |
child: Container( |
decoration: BoxDecoration( |
border: Border.all(width: 10, color: Colors.black38), |
borderRadius: const BorderRadius.all(Radius.circular(8)), |
), |
margin: const EdgeInsets.all(4), |
child: Image.asset('images/pic$imageIndex.jpg'), |
), |
); |
Widget _buildImageRow(int imageIndex) => Row( |
children: [ |
_buildDecoratedImage(imageIndex), |
_buildDecoratedImage(imageIndex + 1), |
], |
);<code_end> |
You can find more Container examples in the tutorial.App source: container<topic_end> |
<topic_start> |
GridView |
Use GridView to lay widgets out as a two-dimensional |
list. GridView provides two pre-fabricated lists, |
or you can build your own custom grid. When a GridView |
detects that its contents are too long to fit the render box, |
it automatically scrolls.<topic_end> |
<topic_start>Summary (GridView) |
info Note |
When displaying a two-dimensional list where it’s important which |
row and column a cell occupies (for example, |
it’s the entry in the “calorie” column for the “avocado” row), use |
Table or DataTable.<topic_end> |
<topic_start>Examples (GridView) |
Uses GridView.extent to create a grid with tiles a maximum |
150 pixels wide.App source: grid_and_listUses GridView.count to create a grid that’s 2 tiles |
wide in portrait mode, and 3 tiles wide in landscape mode. |
The titles are created by setting the footer property for |
each GridTile.Dart code: |
grid_list_demo.dart |
<code_start>Widget _buildGrid() => GridView.extent( |
maxCrossAxisExtent: 150, |
padding: const EdgeInsets.all(4), |
mainAxisSpacing: 4, |
crossAxisSpacing: 4, |
children: _buildGridTileList(30)); |
// The images are saved with names pic0.jpg, pic1.jpg...pic29.jpg. |
// The List.generate() constructor allows an easy way to create |
// a list when objects have a predictable naming pattern. |
List<Container> _buildGridTileList(int count) => List.generate( |
count, (i) => Container(child: Image.asset('images/pic$i.jpg')));<code_end> |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.