text
stringlengths 0
197
|
---|
pixels wide, and 0 to 75 tall.”
|
First child: “OK, then I wish to be 290 pixels wide,
|
and 20 pixels tall.”
|
Widget: “Hmmm, since I want to put my second child below the
|
first one, this leaves only 55 pixels of height for
|
my second child.”
|
Widget: “Hey second child, You must be from 0 to 290 wide,
|
and 0 to 55 tall.”
|
Second child: “OK, I wish to be 140 pixels wide,
|
and 30 pixels tall.”
|
Widget: “Very well. My first child has position x: 5 and y: 5,
|
and my second child has x: 80 and y: 25.”
|
Widget: “Hey parent, I’ve decided that my size is going to be 300
|
pixels wide, and 60 pixels tall.”
|
<topic_end>
|
<topic_start>
|
Limitations
|
Flutter’s layout engine is designed to be a one-pass process.
|
This means that Flutter lays out its widgets very efficiently,
|
but does result in a few limitations:
|
A widget can decide its own size only within the
|
constraints given to it by its parent.
|
This means a widget usually
|
can’t have any size it wants.
|
A widget can’t know and doesn’t decide its own position
|
in the screen, since it’s the widget’s parent who decides
|
the position of the widget.
|
Since the parent’s size and position, in its turn,
|
also depends on its own parent, it’s impossible to
|
precisely define the size and position of any widget
|
without taking into consideration the tree as a whole.
|
If a child wants a different size from its parent and
|
the parent doesn’t have enough information to align it,
|
then the child’s size might be ignored.
|
Be specific when defining alignment.
|
In Flutter, widgets are rendered by their underlying
|
RenderBox objects. Many boxes in Flutter,
|
especially those that just take a single child,
|
pass their constraint on to their children.
|
Generally, there are three kinds of boxes,
|
in terms of how they handle their constraints:
|
Some widgets, for example Container,
|
vary from type to type based on their constructor arguments.
|
The Container constructor defaults
|
to trying to be as big as possible, but if you give it a width,
|
for instance, it tries to honor that and be that particular size.
|
Others, for example Row and Column (flex boxes)
|
vary based on the constraints they are given,
|
as described in the Flex section.
|
<topic_end>
|
<topic_start>
|
Examples
|
For an interactive experience, use the following DartPad.
|
Use the numbered horizontal scrolling bar to switch between
|
29 different examples.
|
<code_start>
|
import 'package:flutter/material.dart';
|
void main() => runApp(const HomePage());
|
const red = Colors.red;
|
const green = Colors.green;
|
const blue = Colors.blue;
|
const big = TextStyle(fontSize: 30);
|
class HomePage extends StatelessWidget {
|
const HomePage({super.key});
|
@override
|
Widget build(BuildContext context) {
|
return const FlutterLayoutArticle([
|
Example1(),
|
Example2(),
|
Example3(),
|
Example4(),
|
Example5(),
|
Example6(),
|
Example7(),
|
Example8(),
|
Example9(),
|
Example10(),
|
Example11(),
|
Example12(),
|
Example13(),
|
Example14(),
|
Example15(),
|
Example16(),
|
Example17(),
|
Example18(),
|
Example19(),
|
Example20(),
|
Example21(),
|
Example22(),
|
Example23(),
|
Example24(),
|
Example25(),
|
Example26(),
|
Example27(),
|
Example28(),
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.