Skip to content

Flutter Cheat Sheet

Last verified May 2026 — runs in your browser
Flutter Cheatsheet
flutter create my_app

Create new Flutter project

Setup
flutter run

Run app on connected device

Setup
flutter build apk --release

Build release APK

Setup
flutter build ios --release

Build release iOS

Setup
flutter pub add package_name

Add a dependency

Setup
flutter pub get

Install dependencies

Setup
flutter doctor

Check Flutter setup

Setup
flutter clean

Clean build artifacts

Setup
Text('Hello', style: TextStyle(fontSize: 20))

Text widget

Widgets
Icon(Icons.star, color: Colors.amber)

Icon widget

Widgets
Image.asset('assets/logo.png')

Load local image

Widgets
Image.network('https://...')

Load remote image

Widgets
ElevatedButton(onPressed: () {}, child: Text('Go'))

Material raised button

Widgets
TextButton(onPressed: () {}, child: Text('Go'))

Flat text button

Widgets
IconButton(icon: Icon(Icons.add), onPressed: () {})

Icon button

Widgets
TextField(decoration: InputDecoration(labelText: 'Name'))

Text input field

Widgets
Switch(value: on, onChanged: (v) {})

Toggle switch

Widgets
Checkbox(value: checked, onChanged: (v) {})

Checkbox

Widgets
CircularProgressIndicator()

Loading spinner

Widgets
Container(padding: EdgeInsets.all(16), color: Colors.blue)

Box with padding and color

Layout
Padding(padding: EdgeInsets.all(8), child: ...)

Wrap with padding

Layout
Center(child: ...)

Center a child

Layout
Column(children: [w1, w2, w3])

Vertical stack

Layout
Row(children: [w1, w2, w3])

Horizontal stack

Layout
Stack(children: [bg, overlay])

Overlapping children (Z-axis)

Layout
Expanded(flex: 2, child: ...)

Fill available space in Row/Column

Layout
SizedBox(height: 16, width: 200)

Fixed-size spacer/box

Layout
Wrap(children: [...])

Wrap to next line when full

Layout
SingleChildScrollView(child: Column(...))

Make content scrollable

Layout
ListView.builder(itemCount: n, itemBuilder: (c, i) => ...)

Scrollable list (lazy)

Layout
GridView.count(crossAxisCount: 2, children: [...])

Grid with fixed columns

Layout
class MyWidget extends StatelessWidget {
  Widget build(BuildContext c) => ...;
}

Stateless widget

State
class MyWidget extends StatefulWidget {
  State<MyWidget> createState() => _S();
}

Stateful widget

State
setState(() { count++; });

Trigger rebuild

State
@override
void initState() { super.initState(); }

Init lifecycle hook

State
@override
void dispose() { ...; super.dispose(); }

Cleanup lifecycle hook

State
final _controller = TextEditingController();

Text field controller

State
ValueNotifier<int>(0) + ValueListenableBuilder

Simple reactive state

State
FutureBuilder(future: fetch(), builder: (c, snap) => ...)

Async data widget

State
StreamBuilder(stream: s, builder: (c, snap) => ...)

Stream data widget

State
Navigator.push(context, MaterialPageRoute(builder: (c) => NextPage()))

Push new route

Navigation
Navigator.pop(context)

Go back

Navigation
Navigator.pushNamed(context, '/details')

Push named route

Navigation
Navigator.pushReplacement(context, ...)

Replace current route

Navigation
final result = await Navigator.push(...); 

Push and wait for result

Navigation
Navigator.pop(context, value);

Return value when popping

Navigation
EdgeInsets.symmetric(horizontal: 16, vertical: 8)

Padding shorthand

Styling
BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(8))

Rounded box

Styling
Theme.of(context).textTheme.headlineLarge

Access theme

Styling
MediaQuery.of(context).size.width

Screen dimensions

Styling
MaterialApp(theme: ThemeData(primarySwatch: Colors.blue))

App with Material theme

Styling
Showing 51 of 51 entries

Flutter Cheat Sheet — Widgets, State Management, Navigation & Layout

Flutter arrived in 2017 with a single tree of immutable widgets rebuilt on every state change, and that mental model still trips up engineers coming from imperative UI frameworks. The cheatsheet below covers 50+ widgets and patterns across setup, widgets, layout, state, navigation, and styling. Most trouble in real Flutter code does not come from forgetting widgets. It comes from quirks that look ordinary until they bite. A `setState` call rebuilds the entire `State` subtree from that widget down, so state placed high in the tree turns a small interaction into a full-page repaint and tanks frame times. `Expanded` and `Flexible` throw at runtime if used outside a `Row`, `Column`, or `Flex` parent — easy to trigger when refactoring a layout into a `Stack` or `Wrap`. Controllers (`TextEditingController`, `ScrollController`, `AnimationController`) need a matching `dispose` in the `State` lifecycle, and forgetting it leaks listeners that fire against deactivated widgets and crash. These are the snippets pulled up while debugging exactly that — the right layout widget, the right lifecycle hook, the right navigator call — without rereading the widgets catalogue from entry one each time.

Common pitfalls in Flutter

A few patterns earn their place near the top of any Flutter screen. Push state as low in the widget tree as it can sensibly live; a `ValueListenableBuilder` around the one rebuilding leaf is dramatically cheaper than a `setState` on the whole page. Mark widget constructors `const` wherever possible, because a `const` widget is identity-equal across rebuilds and Flutter can skip the rebuild entirely, which is the single biggest free performance win in most apps. `BuildContext` is tied to a specific position in the tree, so calling `Navigator.of(context)` after an `await` may operate on a context whose widget has already been removed — the `mounted` check on the `State` exists for exactly this case. `MediaQuery.of(context).size` triggers a rebuild on every keyboard show, rotation, or text-scale change, which is fine when needed but expensive when accidental. `ListView` builds all children eagerly while `ListView.builder` is lazy, so long lists should always use the builder form. The cheatsheet groups all of this into Setup, Widgets, Layout, State, Navigation, and Styling so the right section is one click away.

  • 50+ Flutter widgets and patterns
  • CLI setup commands
  • Layout widgets (Column, Row, Stack)
  • State lifecycle and builders
  • Navigator and named routes
  • One-click copy to clipboard

Free. No signup. Your inputs stay in your browser. Ads via Google AdSense (consent required).

By ·