text
stringlengths
1
372
if you notice the two code samples are identical
except the row and column widget.
the children are the same and this feature
can be exploited to develop rich layouts
that can change overtime with the same children.
<code_start>
@override
widget build(BuildContext context) {
return const row(
mainAxisAlignment: MainAxisAlignment.center,
children: <widget>[
Text('Row one'),
Text('Row two'),
Text('Row three'),
Text('Row four'),
],
);
}
<code_end>
<code_start>
@override
widget build(BuildContext context) {
return const column(
mainAxisAlignment: MainAxisAlignment.center,
children: <widget>[
Text('Column one'),
Text('Column two'),
Text('Column three'),
Text('Column four'),
],
);
<code_end>
<topic_end>
<topic_start>
what is the equivalent of a grid?
the closest equivalent of a grid would be a GridView.
this is much more powerful than what you are used to in Xamarin.Forms.
a GridView provides automatic scrolling when the
content exceeds its viewable space.
<code_start>
@override
widget build(BuildContext context) {
return GridView.count(
// create a grid with 2 columns. if you change the scrollDirection to
// horizontal, this would produce 2 rows.
crossAxisCount: 2,
// generate 100 widgets that display their index in the list.
children: List<Widget>.generate(
100,
(index) {
return center(
child: text(
'item $index',
style: Theme.of(context).textTheme.headlineMedium,
),
);
},
),
);
}
<code_end>
you might have used a grid in Xamarin.Forms
to implement widgets that overlay other widgets.
in flutter, you accomplish this with the stack widget.
this sample creates two icons that overlap each other.
<code_start>
@override
widget build(BuildContext context) {
return const stack(
children: <widget>[
icon(
icons.add_box,
size: 24,
color: colors.black,
),
positioned(
left: 10,
child: icon(
icons.add_circle,
size: 24,
color: colors.black,
),
),
],
);
}
<code_end>
<topic_end>
<topic_start>
what is the equivalent of a ScrollView?
in Xamarin.Forms, a ScrollView wraps around a VisualElement,
and if the content is larger than the device screen, it scrolls.
in flutter, the closest match is the SingleChildScrollView widget.
you simply fill the widget with the content that you want to be scrollable.
<code_start>
@override
widget build(BuildContext context) {
return const SingleChildScrollView(
child: Text('Long content'),
);