Professional Documents
Culture Documents
Cheat Sheet. Do you need simple layout samples for… | by Tomek Polański | Flutter Community | Medium
Save
I present you my set of Flutter layout code snippets. I will keep it short, sweet and
simple with loads of visual examples.
Still, it is work in progress — the catalogue of samples will grow. I will focus more on
the usage of Flutter widgets rather than showcasing the components (Flutter Gallery is
Continue to Medium
great for that!).
If you have an issue with “layouting” your Flutter or you wanna share your snippets
Sign others,
with up Already have
please an account?
drop a line! Sign in
Click “Sign Up” to agree to Medium’s Terms of Service and acknowledge that Medium’s Privacy
Policy applies to you. 67
23K
https://medium.com/flutter-community/flutter-layout-cheat-sheet-5363348d037e 1/57
10/26/22, 7:39 AM Flutter Layout Cheat Sheet. Do you need simple layout samples for… | by Tomek Polański | Flutter Community | Medium
Portuguese by Eddy
In case you are interested in a similar article about Animations, then visit Flutter
Animations Cheat Sheet.
Table of Contents
Row and Column
Stack
Expanded
ConstrainedBox
Align
Container
decoration: BoxDecoration
• image: DecorationImage
• border: Border
• borderRadius: BorderRadius
• shape: BoxShape
• boxShadow: List<BoxShadow>
• gradient: RadialGradient
Continue to Medium
• backgroundBlendMode: BlendMode
Sign up Already have an account? Sign in
Material
• shape:
Click “Sign Up” to BeveledRectangleBorder
agree to Medium’s Terms of Service and acknowledge that Medium’s Privacy
Policy applies to you.
https://medium.com/flutter-community/flutter-layout-cheat-sheet-5363348d037e 2/57
10/26/22, 7:39 AM Flutter Layout Cheat Sheet. Do you need simple layout samples for… | by Tomek Polański | Flutter Community | Medium
Slivers
SizedBox
SafeArea
MainAxisAlignment
Continue to Medium
Click “Sign Up” to agree to Medium’s Terms of Service and acknowledge that Medium’s Privacy
Row /*or Column*/(
children: <Widget>[
https://medium.com/flutter-community/flutter-layout-cheat-sheet-5363348d037e 3/57
10/26/22, 7:39 AM Flutter Layout Cheat Sheet. Do you need simple layout samples for… | by Tomek Polański | Flutter Community | Medium
],
),
Continue to Medium
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Click “Sign
],
Up” to agree to Medium’s Terms of Service and acknowledge that Medium’s Privacy
Policy
),applies to you.
https://medium.com/flutter-community/flutter-layout-cheat-sheet-5363348d037e 4/57
10/26/22, 7:39 AM Flutter Layout Cheat Sheet. Do you need simple layout samples for… | by Tomek Polański | Flutter Community | Medium
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
],
),
Continue to Medium
Click “Sign Up” to agree to Medium’s Terms of Service and acknowledge that Medium’s Privacy
Policy applies to you.
https://medium.com/flutter-community/flutter-layout-cheat-sheet-5363348d037e 5/57
10/26/22, 7:39 AM Flutter Layout Cheat Sheet. Do you need simple layout samples for… | by Tomek Polański | Flutter Community | Medium
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
],
),
Continue to Medium
Click “Sign Up” to agree to Medium’s Terms of Service and acknowledge that Medium’s Privacy
Policy applies to you.
https://medium.com/flutter-community/flutter-layout-cheat-sheet-5363348d037e 6/57
10/26/22, 7:39 AM Flutter Layout Cheat Sheet. Do you need simple layout samples for… | by Tomek Polański | Flutter Community | Medium
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
],
),
Continue to Medium
Click “Sign Up” to agree to Medium’s Terms of Service and acknowledge that Medium’s Privacy
Policy applies to you.
https://medium.com/flutter-community/flutter-layout-cheat-sheet-5363348d037e 7/57
10/26/22, 7:39 AM Flutter Layout Cheat Sheet. Do you need simple layout samples for… | by Tomek Polański | Flutter Community | Medium
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
],
),
Continue to Medium
Click “Sign Up” to agree to Medium’s Terms of Service and acknowledge that Medium’s Privacy
Policy applies to you.
https://medium.com/flutter-community/flutter-layout-cheat-sheet-5363348d037e 8/57
10/26/22, 7:39 AM Flutter Layout Cheat Sheet. Do you need simple layout samples for… | by Tomek Polański | Flutter Community | Medium
You should use CrossAxisAlignment.baseline if you require for the baseline of different
text be aligned.
Row(
crossAxisAlignment: CrossAxisAlignment.baseline,
textBaseline: TextBaseline.alphabetic,
children: <Widget>[
Text(
'Baseline',
style: Theme.of(context).textTheme.display3,
),
Text(
'Baseline',
style: Theme.of(context).textTheme.body1,
Continue ),
to Medium
],
), up
Sign Already have an account? Sign in
Click “Sign Up” to agree to Medium’s Terms of Service and acknowledge that Medium’s Privacy
Policy applies to you.
https://medium.com/flutter-community/flutter-layout-cheat-sheet-5363348d037e 9/57
10/26/22, 7:39 AM Flutter Layout Cheat Sheet. Do you need simple layout samples for… | by Tomek Polański | Flutter Community | Medium
CrossAxisAlignment
Open in app Get started
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
],
),
Continue to Medium
Click “Sign Up” to agree to Medium’s Terms of Service and acknowledge that Medium’s Privacy
Policy applies to you.
https://medium.com/flutter-community/flutter-layout-cheat-sheet-5363348d037e 10/57
10/26/22, 7:39 AM Flutter Layout Cheat Sheet. Do you need simple layout samples for… | by Tomek Polański | Flutter Community | Medium
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
],
),
Continue to Medium
Click “Sign Up” to agree to Medium’s Terms of Service and acknowledge that Medium’s Privacy
Policy applies to you.
https://medium.com/flutter-community/flutter-layout-cheat-sheet-5363348d037e 11/57
10/26/22, 7:39 AM Flutter Layout Cheat Sheet. Do you need simple layout samples for… | by Tomek Polański | Flutter Community | Medium
crossAxisAlignment: CrossAxisAlignment.end,
children: <Widget>[
],
),
Continue to Medium
Click “Sign Up” to agree to Medium’s Terms of Service and acknowledge that Medium’s Privacy
Policy applies to you.
https://medium.com/flutter-community/flutter-layout-cheat-sheet-5363348d037e 12/57
10/26/22, 7:39 AM Flutter Layout Cheat Sheet. Do you need simple layout samples for… | by Tomek Polański | Flutter Community | Medium
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
],
),
Continue to Medium
MainAxisSize
Sign up Already have an account? Sign in
Click “Sign Up” to agree to Medium’s Terms of Service and acknowledge that Medium’s Privacy
Policy applies to you.
https://medium.com/flutter-community/flutter-layout-cheat-sheet-5363348d037e 13/57
10/26/22, 7:39 AM Flutter Layout Cheat Sheet. Do you need simple layout samples for… | by Tomek Polański | Flutter Community | Medium
mainAxisSize: MainAxisSize.max,
children: <Widget>[
],
),
Continue to Medium
Click “Sign Up” to agree to Medium’s Terms of Service and acknowledge that Medium’s Privacy
Policy applies to you.
https://medium.com/flutter-community/flutter-layout-cheat-sheet-5363348d037e 14/57
10/26/22, 7:39 AM Flutter Layout Cheat Sheet. Do you need simple layout samples for… | by Tomek Polański | Flutter Community | Medium
mainAxisSize: MainAxisSize.min,
children: <Widget>[
],
),
Continue to Medium
IntrinsicWidth and IntrinsicHeight
Sign up Already have an account? Sign in
Want all the widgets inside Row or Column to be as tall/wide as the tallest/widest
widget?
Click Search
“Sign Up” no
to agree more! Terms of Service and acknowledge that Medium’s Privacy
to Medium’s
Policy applies to you.
In case you have this kind of layout:
https://medium.com/flutter-community/flutter-layout-cheat-sheet-5363348d037e 15/57
10/26/22, 7:39 AM Flutter Layout Cheat Sheet. Do you need simple layout samples for… | by Tomek Polański | Flutter Community | Medium
return Scaffold(
body: Center(
child: Column(
children: <Widget>[
RaisedButton(
onPressed: () {},
child: Text('Short'),
),
RaisedButton(
onPressed: () {},
),
RaisedButton(
Sign up ),
),
Click “Sign ),
Up” to agree to Medium’s Terms of Service and acknowledge that Medium’s Privacy
Policy applies
);
to you.
}
https://medium.com/flutter-community/flutter-layout-cheat-sheet-5363348d037e 16/57
10/26/22, 7:39 AM Flutter Layout Cheat Sheet. Do you need simple layout samples for… | by Tomek Polański | Flutter Community | Medium
return Scaffold(
body: Center(
child: IntrinsicWidth(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
RaisedButton(
child: Text('Short'),
),
Sign up AlreadyRaisedButton(
child:Terms
Click “Sign Up” to agree to Medium’s Text('A bit
of Service andLonger'),
RaisedButton(
onPressed: () {},
https://medium.com/flutter-community/flutter-layout-cheat-sheet-5363348d037e 17/57
10/26/22, 7:39 AM Flutter Layout Cheat Sheet. Do you need simple layout samples for… | by Tomek Polański | Flutter Community | Medium
),
Open in app Get started
],
),
),
),
);
In case you have a similar problem but you would like to have all the widgets as tall as
the tallest just use a combination of IntrinsicHeight and Row widgets.
Stack
Perfect for overlaying Widgets on top of each other
Continue to Medium
Click “Sign Up” to agree to Medium’s Terms of Service and acknowledge that Medium’s Privacy
Policy applies to you.
https://medium.com/flutter-community/flutter-layout-cheat-sheet-5363348d037e 18/57
10/26/22, 7:39 AM Flutter Layout Cheat Sheet. Do you need simple layout samples for… | by Tomek Polański | Flutter Community | Medium
@override
Open in app Get started
Widget build(BuildContext context) {
);
return Stack(
fit: StackFit.expand,
children: <Widget>[
main,
Banner(
location: BannerLocation.topStart,
),
Banner(
location: BannerLocation.topEnd,
),
Banner(
location: BannerLocation.bottomStart,
),
Banner(
location: BannerLocation.bottomEnd,
),
],
);
With your own Widgets, you need to place them in Positioned Widget
Continue to Medium
Click “Sign Up” to agree to Medium’s Terms of Service and acknowledge that Medium’s Privacy
Policy applies to you.
https://medium.com/flutter-community/flutter-layout-cheat-sheet-5363348d037e 19/57
10/26/22, 7:39 AM Flutter Layout Cheat Sheet. Do you need simple layout samples for… | by Tomek Polański | Flutter Community | Medium
return Scaffold(
body: Stack(
fit: StackFit.expand,
children: <Widget>[
Material(color: Colors.yellowAccent),
Positioned(
top: 0,
left: 0,
),
Positioned(
top: 340,
left: 250,
),
Sign up ],
Already have an account? Sign in
),
);
Click}“Sign Up” to agree to Medium’s Terms of Service and acknowledge that Medium’s Privacy
Policy applies to you.
https://medium.com/flutter-community/flutter-layout-cheat-sheet-5363348d037e 20/57
10/26/22, 7:39 AM Flutter Layout Cheat Sheet. Do you need simple layout samples for… | by Tomek Polański | Flutter Community | Medium
If you don’t want to guess the top/bottom values you can use LayoutBuilder to retrieve
them
return Scaffold(
body: LayoutBuilder(
Stack(
children: <Widget>[
Sign up AlreadyMaterial(color:
have an account? SignColors.yellowAccent),
in
Positioned(
top: 0,
Click “Sign Up” to agree to Medium’s Terms of Service and acknowledge that Medium’s Privacy
child: Icon(Icons.star, size: iconSize),
Positioned(
https://medium.com/flutter-community/flutter-layout-cheat-sheet-5363348d037e 21/57
10/26/22, 7:39 AM Flutter Layout Cheat Sheet. Do you need simple layout samples for… | by Tomek Polański | Flutter Community | Medium
),
],
),
),
);
Expanded
Expanded works with Flex\Flexbox layout and is great for distributing space between
multiple items.
Continue to Medium
Click “Sign Up” to agree to Medium’s Terms of Service and acknowledge that Medium’s Privacy
Policy applies to you.
https://medium.com/flutter-community/flutter-layout-cheat-sheet-5363348d037e 22/57
10/26/22, 7:39 AM Flutter Layout Cheat Sheet. Do you need simple layout samples for… | by Tomek Polański | Flutter Community | Medium
Row(
Open in app Get started
children: <Widget>[
Expanded(
child: Container(
),
flex: 3,
),
Expanded(
child: Container(
),
flex: 2,
),
Expanded(
child: Container(
),
flex: 1,
),
],
),
ConstrainedBox
By default, most of the widgets will use as little space as possible:
Continue to Medium
Click “Sign Up” to agree to Medium’s Terms of Service and acknowledge that Medium’s Privacy
Policy applies to you.
https://medium.com/flutter-community/flutter-layout-cheat-sheet-5363348d037e 23/57
10/26/22, 7:39 AM Flutter Layout Cheat Sheet. Do you need simple layout samples for… | by Tomek Polański | Flutter Community | Medium
Continue to Medium
Click “Sign Up” to agree to Medium’s Terms of Service and acknowledge that Medium’s Privacy
Policy applies to you.
https://medium.com/flutter-community/flutter-layout-cheat-sheet-5363348d037e 24/57
10/26/22, 7:39 AM Flutter Layout Cheat Sheet. Do you need simple layout samples for… | by Tomek Polański | Flutter Community | Medium
ConstrainedBox(
constraints: BoxConstraints.expand(),
color: Colors.yellow,
),
),
Using BoxConstraints you specify how much space a widget can have — you specify
Continue to height
min / max of Medium / width .
https://medium.com/flutter-community/flutter-layout-cheat-sheet-5363348d037e 25/57
10/26/22, 7:39 AM Flutter Layout Cheat Sheet. Do you need simple layout samples for… | by Tomek Polański | Flutter Community | Medium
ConstrainedBox(
color: Colors.yellow,
),
),
ConstrainedBox(
Continue to Medium
constraints: BoxConstraints(
minWidth: double.infinity,
maxWidth: double.infinity,
Sign upminHeight:
Already have an account? Sign in
300,
maxHeight: 300,
),
Click “Sign Up” to agree to Medium’s Terms of Service and acknowledge that Medium’s Privacy
child: const Card(
https://medium.com/flutter-community/flutter-layout-cheat-sheet-5363348d037e 26/57
10/26/22, 7:39 AM Flutter Layout Cheat Sheet. Do you need simple layout samples for… | by Tomek Polański | Flutter Community | Medium
color: Colors.yellow,
),
Open in app Get started
),
Align
Sometimes you struggle to set our widget to a proper size — for example, it is
constantly stretch when you do not want to:
Continue to Medium
https://medium.com/flutter-community/flutter-layout-cheat-sheet-5363348d037e 27/57
10/26/22, 7:39 AM Flutter Layout Cheat Sheet. Do you need simple layout samples for… | by Tomek Polański | Flutter Community | Medium
return Scaffold(
body: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Align(
child: RaisedButton(
onPressed: () {},
),
Continue to Medium
),
],
Sign up),
Already have an account? Sign in
);
}
Click “Sign Up” to agree to Medium’s Terms of Service and acknowledge that Medium’s Privacy
Policy applies to you.
https://medium.com/flutter-community/flutter-layout-cheat-sheet-5363348d037e 28/57
10/26/22, 7:39 AM Flutter Layout Cheat Sheet. Do you need simple layout samples for… | by Tomek Polański | Flutter Community | Medium
Always when your widget does not listen to the constraints that you try to set up, first
Open in app Get started
try to wrap it with Align .
Container
One of the most used Widgets — and for good reasons:
Continue to Medium
return
Click “Sign Scaffold(
Up” to agree to Medium’s Terms of Service and acknowledge that Medium’s Privacy
appBar:
Policy applies to you. AppBar(title: Text('Container as a layout')),
body: Container(
https://medium.com/flutter-community/flutter-layout-cheat-sheet-5363348d037e 29/57
10/26/22, 7:39 AM Flutter Layout Cheat Sheet. Do you need simple layout samples for… | by Tomek Polański | Flutter Community | Medium
color: Colors.yellowAccent,
child: Text("Hi"),
Open in app Get started
),
);
If you want to stretch the Container to match its parent, use double.infinity for the
height and width properties
return Scaffold(
Continue to Medium
body: Container(
height: double.infinity,
color: Colors.yellowAccent,
child: Text("Hi"),
Click “Sign Up” to agree to Medium’s Terms of Service and acknowledge that Medium’s Privacy
),
}
https://medium.com/flutter-community/flutter-layout-cheat-sheet-5363348d037e 30/57
10/26/22, 7:39 AM Flutter Layout Cheat Sheet. Do you need simple layout samples for… | by Tomek Polański | Flutter Community | Medium
Container as decoration
You can use color property to affect Container ’s background but decoration and
foregroundDecoration . (With those two properties, you can completely change how
Containe r looks like but I will be talking about different decorations later as it quite a
big topic)
decoration
Continue to Medium
Widget build(BuildContext context) {
width: double.infinity,
https://medium.com/flutter-community/flutter-layout-cheat-sheet-5363348d037e 31/57
10/26/22, 7:39 AM Flutter Layout Cheat Sheet. Do you need simple layout samples for… | by Tomek Polański | Flutter Community | Medium
child: Text("Hi"),
Open in app Get started
),
);
return Scaffold(
Continue to Medium
appBar: AppBar(title: Text('Container.foregroundDecoration')),
body: Container(
width: double.infinity,
color: Colors.red.withOpacity(0.5),
),
https://medium.com/flutter-community/flutter-layout-cheat-sheet-5363348d037e 32/57
10/26/22, 7:39 AM Flutter Layout Cheat Sheet. Do you need simple layout samples for… | by Tomek Polański | Flutter Community | Medium
child: Text("Hi"),
),
Open in app Get started
);
Container as Transform
If you don’t want to use Transform widget to change your layout, you can use transform
return Scaffold(
Continue to Medium
appBar: AppBar(title: Text('Container.transform')),
body: Container(
Click “Sign Up” to agree to Medium’s Terms of Service and acknowledge that Medium’s Privacy
decoration: BoxDecoration(color: Colors.yellowAccent),
"Hi",
https://medium.com/flutter-community/flutter-layout-cheat-sheet-5363348d037e 33/57
10/26/22, 7:39 AM Flutter Layout Cheat Sheet. Do you need simple layout samples for… | by Tomek Polański | Flutter Community | Medium
textAlign: TextAlign.center,
),
Open in app Get started
),
);
BoxDecoration
The decoration is usually used on a Container widget to change how the container
looks.
image: DecorationImage
Puts an image as a background:
Continue to Medium
Click “Sign Up” to agree to Medium’s Terms of Service and acknowledge that Medium’s Privacy
Policy applies to you.
https://medium.com/flutter-community/flutter-layout-cheat-sheet-5363348d037e 34/57
10/26/22, 7:39 AM Flutter Layout Cheat Sheet. Do you need simple layout samples for… | by Tomek Polański | Flutter Community | Medium
Scaffold(
Open in app Get started
appBar: AppBar(title: Text('image: DecorationImage')),
body: Center(
child: Container(
height: 200,
width: 200,
decoration: BoxDecoration(
color: Colors.yellow,
image: DecorationImage(
fit: BoxFit.fitWidth,
image: NetworkImage(
'https://flutter.io/images/catalog-widget-
placeholder.png',
),
),
),
),
),
);
border: Border
Specifies how should the border of the Container look like.
Continue to Medium
Click “Sign Up” to agree to Medium’s Terms of Service and acknowledge that Medium’s Privacy
Policy applies to you.
https://medium.com/flutter-community/flutter-layout-cheat-sheet-5363348d037e 35/57
10/26/22, 7:39 AM Flutter Layout Cheat Sheet. Do you need simple layout samples for… | by Tomek Polański | Flutter Community | Medium
Scaffold(
body: Center(
child: Container(
height: 200,
width: 200,
decoration: BoxDecoration(
color: Colors.yellow,
),
),
),
);
Continue to Medium
borderRadius: BorderRadius
Sign up border
Enables Already have an account?
corners Sign in
to be rounded.
Click “Sign Up” to agree to Medium’s Terms of Service and acknowledge that Medium’s Privacy
borderRadius does not work if the shape of the decoration is BoxShape.circle
Policy applies to you.
https://medium.com/flutter-community/flutter-layout-cheat-sheet-5363348d037e 36/57
10/26/22, 7:39 AM Flutter Layout Cheat Sheet. Do you need simple layout samples for… | by Tomek Polański | Flutter Community | Medium
Scaffold(
body: Center(
child: Container(
height: 200,
width: 200,
decoration: BoxDecoration(
color: Colors.yellow,
borderRadius: BorderRadius.all(Radius.circular(18)),
),
),
),
);
Continue to Medium
shape: BoxShape
Sign up Already have an account? Sign in
Box decoration can be either a rectangle/square or an ellipse/circle.
Click “Sign Up” to agree to Medium’s Terms of Service and acknowledge that Medium’s Privacy
Policy applies
For any to you.
other shape, you can use ShapeDecoration instead of BoxDecoration
https://medium.com/flutter-community/flutter-layout-cheat-sheet-5363348d037e 37/57
10/26/22, 7:39 AM Flutter Layout Cheat Sheet. Do you need simple layout samples for… | by Tomek Polański | Flutter Community | Medium
Scaffold(
body: Center(
child: Container(
height: 200,
width: 200,
decoration: BoxDecoration(
color: Colors.yellow,
shape: BoxShape.circle,
),
),
),
);
Continue to Medium
boxShadow: List<BoxShadow>
Sign up
Adds Already
shadow have
to the an account?
Container. Sign in
Click “Sign Up” to agree to Medium’s Terms of Service and acknowledge that Medium’s Privacy
This parameter is a list because you can specify multiple different shadows and merge
Policy applies to you.
them together.
https://medium.com/flutter-community/flutter-layout-cheat-sheet-5363348d037e 38/57
10/26/22, 7:39 AM Flutter Layout Cheat Sheet. Do you need simple layout samples for… | by Tomek Polański | Flutter Community | Medium
Scaffold(
body: Center(
child: Container(
height: 200,
width: 200,
decoration: BoxDecoration(
color: Colors.yellow,
boxShadow: const [
BoxShadow(blurRadius: 10),
],
),
),
),
);
Continue to Medium
https://medium.com/flutter-community/flutter-layout-cheat-sheet-5363348d037e 39/57
10/26/22, 7:39 AM Flutter Layout Cheat Sheet. Do you need simple layout samples for… | by Tomek Polański | Flutter Community | Medium
LinearGradient
Scaffold(
body: Center(
child: Container(
height: 200,
width: 200,
decoration: BoxDecoration(
gradient: LinearGradient(
colors: const [
Colors.red,
Colors.blue,
],
),
Continue ),
to Medium
),
),
Click “Sign Up” to agree to Medium’s Terms of Service and acknowledge that Medium’s Privacy
Policy applies to you.
https://medium.com/flutter-community/flutter-layout-cheat-sheet-5363348d037e 40/57
10/26/22, 7:39 AM Flutter Layout Cheat Sheet. Do you need simple layout samples for… | by Tomek Polański | Flutter Community | Medium
RadialGradient
Scaffold(
body: Center(
child: Container(
height: 200,
width: 200,
decoration: BoxDecoration(
gradient: RadialGradient(
),
),
),
Continue
),
to Medium
);
Click “Sign Up” to agree to Medium’s Terms of Service and acknowledge that Medium’s Privacy
Policy applies to you.
https://medium.com/flutter-community/flutter-layout-cheat-sheet-5363348d037e 41/57
10/26/22, 7:39 AM Flutter Layout Cheat Sheet. Do you need simple layout samples for… | by Tomek Polański | Flutter Community | Medium
SweepGradient
Scaffold(
body: Center(
child: Container(
height: 200,
width: 200,
decoration: BoxDecoration(
gradient: SweepGradient(
colors: const [
Colors.blue,
Colors.green,
Colors.yellow,
Colors.red,
],
Sign up Already
),
have an account? Sign in
),
),
Click “Sign Up” to agree to Medium’s Terms of Service and acknowledge that Medium’s Privacy
),
to you.
Policy applies
);
https://medium.com/flutter-community/flutter-layout-cheat-sheet-5363348d037e 42/57
10/26/22, 7:39 AM Flutter Layout Cheat Sheet. Do you need simple layout samples for… | by Tomek Polański | Flutter Community | Medium
With backgroundBlendMode you can use a long list of algorithms specified in BlendMode
enum.
Continue to Medium
Click “Sign Up” to agree to Medium’s Terms of Service and acknowledge that Medium’s Privacy
body: Center(
height: 200,
https://medium.com/flutter-community/flutter-layout-cheat-sheet-5363348d037e 43/57
10/26/22, 7:39 AM Flutter Layout Cheat Sheet. Do you need simple layout samples for… | by Tomek Polański | Flutter Community | Medium
width: 200,
foregroundDecoration: BoxDecoration(
Open in app Get started
backgroundBlendMode: BlendMode.exclusion,
gradient: LinearGradient(
colors: const [
Colors.red,
Colors.blue,
],
),
),
child: Image.network(
'https://flutter.io/images/catalog-widget-placeholder.png',
),
),
),
);
backgroundBlendMode does not affect only the Container it’s located in.
backgroundBlendMode changes the color of anything that is up the widget tree from the
Container .
The following code has a parent Container that draws an image and child Container
that uses backgroundBlendMode . Still, you would get the same effect as previously.
Continue to Medium
Click “Sign Up” to agree to Medium’s Terms of Service and acknowledge that Medium’s Privacy
Policy applies to you.
https://medium.com/flutter-community/flutter-layout-cheat-sheet-5363348d037e 44/57
10/26/22, 7:39 AM Flutter Layout Cheat Sheet. Do you need simple layout samples for… | by Tomek Polański | Flutter Community | Medium
Scaffold(
body: Center(
child: Container(
decoration: BoxDecoration(
image: DecorationImage(
image: NetworkImage(
'https://flutter.io/images/catalog-widget-
placeholder.png',
),
),
),
child: Container(
height: 200,
width: 200,
Continue toforegroundDecoration:
Medium BoxDecoration(
backgroundBlendMode: BlendMode.exclusion,
Sign up gradient:
Already LinearGradient(
Colors.red,
Click “Sign Up” to agree to Medium’s Terms of Service and acknowledge that Medium’s Privacy
Colors.blue,
),
https://medium.com/flutter-community/flutter-layout-cheat-sheet-5363348d037e 45/57
10/26/22, 7:39 AM Flutter Layout Cheat Sheet. Do you need simple layout samples for… | by Tomek Polański | Flutter Community | Medium
),
),
Open in app Get started
),
),
);
Material
Border with cut corners
Continue to Medium
Scaffold(
Sign appBar:
up AppBar(title: Text('shape: BeveledRectangleBorder')),
child: Material(
https://medium.com/flutter-community/flutter-layout-cheat-sheet-5363348d037e 46/57
10/26/22, 7:39 AM Flutter Layout Cheat Sheet. Do you need simple layout samples for… | by Tomek Polański | Flutter Community | Medium
),
color: Colors.yellow,
Open in app Get started
child: Container(
height: 200,
width: 200,
),
),
),
);
Slivers
SliverFillRemaining
This Widget is irreplaceable when you want to center your content even if there is not
enough space for it. Interactive example
Continue to Medium
Click “Sign Up” to agree to Medium’s Terms of Service and acknowledge that Medium’s Privacy
Policy applies to you.
Enough vertical space
https://medium.com/flutter-community/flutter-layout-cheat-sheet-5363348d037e 47/57
10/26/22, 7:39 AM Flutter Layout Cheat Sheet. Do you need simple layout samples for… | by Tomek Polański | Flutter Community | Medium
Scaffold(
Open in app Get started
appBar: AppBar(title: Text('SliverFillRemaining')),
body: CustomScrollView(
slivers: [
SliverFillRemaining(
hasScrollBody: false,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: const [
FlutterLogo(size: 200),
Text(
textAlign: TextAlign.center,
),
],
),
),
],
),
);
In case there is no enough space for the centred content, SliverFillRemaining will
become scrollable:
Continue to Medium
Not enough vertical space
Sign up Already have an account? Sign in
If it was not for SliverFillRemaining , the content would overflow like this:
Click “Sign Up” to agree to Medium’s Terms of Service and acknowledge that Medium’s Privacy
Policy applies to you.
https://medium.com/flutter-community/flutter-layout-cheat-sheet-5363348d037e 48/57
10/26/22, 7:39 AM Flutter Layout Cheat Sheet. Do you need simple layout samples for… | by Tomek Polański | Flutter Community | Medium
Continue to Medium
Click “Sign Up” to agree to Medium’s Terms of Service and acknowledge that Medium’s Privacy
Policy applies to you.
https://medium.com/flutter-community/flutter-layout-cheat-sheet-5363348d037e 49/57
10/26/22, 7:39 AM Flutter Layout Cheat Sheet. Do you need simple layout samples for… | by Tomek Polański | Flutter Community | Medium
Continue to Medium
Click “Sign Up” to agree to Medium’s Terms of Service and acknowledge that Medium’s Privacy
Policy applies to you.
https://medium.com/flutter-community/flutter-layout-cheat-sheet-5363348d037e 50/57
10/26/22, 7:39 AM Flutter Layout Cheat Sheet. Do you need simple layout samples for… | by Tomek Polański | Flutter Community | Medium
Scaffold(
body: CustomScrollView(
slivers: [
SliverList(
delegate: SliverChildListDelegate(const [
]),
),
SliverFillRemaining(
hasScrollBody: false,
color: Colors.yellowAccent,
child: Column(
Sign up AlreadymainAxisAlignment:
have an account? Sign in MainAxisAlignment.center,
children: const [
FlutterLogo(size:
Click “Sign Up” to agree to Medium’s 200),
https://medium.com/flutter-community/flutter-layout-cheat-sheet-5363348d037e 51/57
10/26/22, 7:39 AM Flutter Layout Cheat Sheet. Do you need simple layout samples for… | by Tomek Polański | Flutter Community | Medium
textAlign: TextAlign.center,
Open in app Get started
),
],
),
),
),
],
),
);
SizedBox
It’s one of the simplest but most useful Widgets
SizedBox as ConstrainedBox
SizedBox can work in a similar fashion as ConstrainedBox
Continue to Medium
Click “Sign Up” to agree to Medium’s Terms of Service and acknowledge that Medium’s Privacy
Policy applies to you.
https://medium.com/flutter-community/flutter-layout-cheat-sheet-5363348d037e 52/57
10/26/22, 7:39 AM Flutter Layout Cheat Sheet. Do you need simple layout samples for… | by Tomek Polański | Flutter Community | Medium
SizedBox.expand(
Open in app Get started
child: Card(
color: Colors.yellowAccent,
),
),
SizedBox as padding
When in need of adding padding or margin, you might choose Padding or Container
widgets. But they can be more verbose and less readable than adding a Sizedbox
Continue to Medium
ClickColumn(
“Sign Up” to agree to Medium’s Terms of Service and acknowledge that Medium’s Privacy
children:
Policy applies <Widget>[
to you.
Icon(Icons.star, size: 50),
https://medium.com/flutter-community/flutter-layout-cheat-sheet-5363348d037e 53/57
10/26/22, 7:39 AM Flutter Layout Cheat Sheet. Do you need simple layout samples for… | by Tomek Polański | Flutter Community | Medium
],
),
Continue
Widget to Medium
build(BuildContext context) {
return Scaffold(
Sign upappBar:AlreadyAppBar(
Click “Sign ),
Up” to agree to Medium’s Terms of Service and acknowledge that Medium’s Privacy
Policy applies to you.isVisible
body:
? Icon(Icons.star, size: 150)
https://medium.com/flutter-community/flutter-layout-cheat-sheet-5363348d037e 54/57
10/26/22, 7:39 AM Flutter Layout Cheat Sheet. Do you need simple layout samples for… | by Tomek Polański | Flutter Community | Medium
: const SizedBox(),
);
Open in app Get started
}
Because SizedBox has a const constructor, using const SizedBox() is really cheap**.
** One cheaper solution would be to use Opacity widget and change the opacity value
to 0.0 . The drawback of this solution is that the given widget would be only invisible,
still would occupy the space.
SafeArea
On different platforms, there are special areas like Status Bar on Android or the Notch
on iPhone X that we might avoid drawing under.
Continue to Medium
Click “Sign Up” to agree to Medium’s Terms of Service and acknowledge that Medium’s Privacy
Policy applies to you.
https://medium.com/flutter-community/flutter-layout-cheat-sheet-5363348d037e 55/57
10/26/22, 7:39 AM Flutter Layout Cheat Sheet. Do you need simple layout samples for… | by Tomek Polański | Flutter Community | Medium
return Material(
color: Colors.blue,
child: SafeArea(
child: SizedBox.expand(
),
),
);
Continue to Medium
https://medium.com/flutter-community/flutter-layout-cheat-sheet-5363348d037e 56/57
10/26/22, 7:39 AM Flutter Layout Cheat Sheet. Do you need simple layout samples for… | by Tomek Polański | Flutter Community | Medium
twitter.com
Continue to Medium
Click “Sign Up” to agree to Medium’s Terms of Service and acknowledge that Medium’s Privacy
Policy applies to you.
https://medium.com/flutter-community/flutter-layout-cheat-sheet-5363348d037e 57/57