flutter create my_app
Create new Flutter project
flutter run
Run app on connected device
flutter build apk --release
Build release APK
flutter build ios --release
Build release iOS
flutter pub add package_name
Add a dependency
flutter pub get
Install dependencies
flutter doctor
Check Flutter setup
flutter clean
Clean build artifacts
Text('Hello', style: TextStyle(fontSize: 20)) Text widget
Icon(Icons.star, color: Colors.amber)
Icon widget
Image.asset('assets/logo.png') Load local image
Image.network('https://...') Load remote image
ElevatedButton(onPressed: () {}, child: Text('Go')) Material raised button
TextButton(onPressed: () {}, child: Text('Go')) Flat text button
IconButton(icon: Icon(Icons.add), onPressed: () {}) Icon button
TextField(decoration: InputDecoration(labelText: 'Name'))
Text input field
Switch(value: on, onChanged: (v) {}) Toggle switch
Checkbox(value: checked, onChanged: (v) {}) Checkbox
CircularProgressIndicator()
Loading spinner
Container(padding: EdgeInsets.all(16), color: Colors.blue)
Box with padding and color
Padding(padding: EdgeInsets.all(8), child: ...)
Wrap with padding
Center(child: ...)
Center a child
Column(children: [w1, w2, w3])
Vertical stack
Row(children: [w1, w2, w3])
Horizontal stack
Stack(children: [bg, overlay])
Overlapping children (Z-axis)
Expanded(flex: 2, child: ...)
Fill available space in Row/Column
SizedBox(height: 16, width: 200)
Fixed-size spacer/box
Wrap(children: [...])
Wrap to next line when full
SingleChildScrollView(child: Column(...))
Make content scrollable
ListView.builder(itemCount: n, itemBuilder: (c, i) => ...)
Scrollable list (lazy)
GridView.count(crossAxisCount: 2, children: [...])
Grid with fixed columns
class MyWidget extends StatelessWidget {
Widget build(BuildContext c) => ...;
} Stateless widget
class MyWidget extends StatefulWidget {
State<MyWidget> createState() => _S();
} Stateful widget
setState(() { count++; }); Trigger rebuild
@override
void initState() { super.initState(); } Init lifecycle hook
@override
void dispose() { ...; super.dispose(); } Cleanup lifecycle hook
final _controller = TextEditingController();
Text field controller
ValueNotifier<int>(0) + ValueListenableBuilder
Simple reactive state
FutureBuilder(future: fetch(), builder: (c, snap) => ...)
Async data widget
StreamBuilder(stream: s, builder: (c, snap) => ...)
Stream data widget
Navigator.push(context, MaterialPageRoute(builder: (c) => NextPage()))
Push new route
Navigator.pop(context)
Go back
Navigator.pushNamed(context, '/details')
Push named route
Navigator.pushReplacement(context, ...)
Replace current route
final result = await Navigator.push(...);
Push and wait for result
Navigator.pop(context, value);
Return value when popping
EdgeInsets.symmetric(horizontal: 16, vertical: 8)
Padding shorthand
BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(8))
Rounded box
Theme.of(context).textTheme.headlineLarge
Access theme
MediaQuery.of(context).size.width
Screen dimensions
MaterialApp(theme: ThemeData(primarySwatch: Colors.blue))
App with Material theme
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 Marco B. ·